xcode – [IOS SDK] – touchesBegan与特定对象?

前端之家收集整理的这篇文章主要介绍了xcode – [IOS SDK] – touchesBegan与特定对象?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我触摸屏幕上的任何地方触摸触发事件时触发.但我无法管理如何像UI ImageView一样触摸特定对象?

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

 UITouch *touch = [[event allTouches] anyObject];

 CGPoint location = [touch locationInView: touch.view];

 imageView.center = location;

}

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

 [self touchesBegan:touches withEvent:event];

}

解决方法

好的,找到了解决方案,这里是代码

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

    UITouch *touch = [[event allTouches] anyObject];

    if ([touch view] == imageView) {

        CGPoint location = [touch locationInView: self.view];

        imageView.center = location;

    }

}

猜你在找的Xcode相关文章