xcode - [IOS SDK]-touchesBegan 以特定对象开始?

标签 xcode ios4 touchesbegan nsset touchesmoved

当我触摸屏幕上的任何地方时触发 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/

相关文章:

ios - UIView 未被调用

xcode - 为什么在 Swift 中用关键字 "let"声明常量?

Xcode 部署目标设置

iphone - 我的 AppDelegate 未调用 FBConnect 的 handleOpenURL 方法

iphone - 在 iOS 4.3.3 的 iPhone 上禁用自动锁定

iOS 如何制作图书应用程序?导航 Controller + 文本 + 索引

ios - 无法在 iOS 的 viewController 中调用 touchesBegan/touchesMoved 方法

ios - GooglePlaceAPI 错误 : -6 in iOS

xcode - 升级到 Xcode 4 后出现丢失文件警告

iphone - 如何使 'touchesBegan' 方法适用于特定 View ?