相关疑难解决方法(0)

touchesBegan,touchesEnded,touchesMoved移动UIView

我需要拖动我的UIView对象.我使用此代码,但它不起作用

float oldX, oldY;
BOOL dragging;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self];

    if ([[touch.view class] isSubclassOfClass:[UILabel class]]) {
        UILabel *label = (UILabel *)touch.view;
        if (CGRectContainsPoint(label.frame, touchLocation)) {
            dragging = YES;
            oldX = touchLocation.x;
            oldY = touchLocation.y;
        }
    }


}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    dragging = NO;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self];

    if ([[touch.view class] …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uiview touchesbegan ios

20
推荐指数
3
解决办法
8万
查看次数

标签 统计

ios ×1

objective-c ×1

touchesbegan ×1

uiview ×1

xcode ×1