当我触摸屏幕上的任何地方时触发 touchesBegan 事件。但是如果我像 UIImageView 一样触摸特定对象,我无法管理如何?
-(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 - [IOS SDK]-touchesBegan 以特定对象开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4473373/