使用 UITouch 检测特定对象
你好 。我正在尝试使用 UITouch
移动 UIImageView
对象,但代码有问题,如何实现 UITouch 来仅检测我的 UIImageView 对象?
**imageA 它是我的 UIImageView
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *toucheA = [[event allTouches] anyObject];
if ([toucheA view] == imageA) {
CGPoint location = [toucheA locationInView:self];
imageA.center = location;
}
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
CGPoint postion = imageA.center;
imageA.center = postion;
postion.y = 230;
imageA.center = postion;
}
但不起作用!
HI . i am trying to move an UIImageView
object with UITouch
and have problem with the code how can i implement UITouch to detect only my UIImageView object ?
**imageA it my UIImageView
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *toucheA = [[event allTouches] anyObject];
if ([toucheA view] == imageA) {
CGPoint location = [toucheA locationInView:self];
imageA.center = location;
}
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
CGPoint postion = imageA.center;
imageA.center = postion;
postion.y = 230;
imageA.center = postion;
}
but doesn't work !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以通过子类化来创建自定义 UIImageView 并在自定义视图中接收您想要的触摸事件。
一般来说,最上面的视图将接收触摸事件。如果视图处理了触摸事件并且没有将事件传递给另一个视图,那么它后面的其他视图就不可能接收到任何触摸事件。如果视图无法处理触摸事件,它将通过调用 super 的方法来传递该事件。
I think you can make a custom UIImageView by subclassing and receive touch event you want inside the custom view.
Generally, the top most view will receiver the touch event. If the view process the touch event and doesn't pass the event to another view, then the others view behind it are impossible to receive any touch event. If the view cannot deal with the touch event, it will pass that by calling super's method.