在UIView中,有几个UIImageView对象的 subview 。
因为我需要检测来自 UIImageView 和 UIView 剩余区域的触摸事件。
我可以在 UIView 和 UIImagView 中同时实现触摸事件吗?
谢谢。
最佳答案
根据您的评论,我认为您应该考虑手势识别器。使用 UITapGestureRecognizer
识别并响应 View 上的点击。
UITapGestureRecognizer *tapGesture;
tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOnView:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[view addGesture:tapGesture];
[tapGesture release];
...
tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOnImage:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[imageView addGesture:tapGesture];
[tapGesture release];
...
定义 -(void)handleTapOnView:(UITapGestureRecognizer*)gesture
和 -(void)handleTapOnImage:(UITapGestureRecognizer*)gesture
并处理那里的触摸。
还有其他类型的手势。您可以阅读有关它们的更多信息 here .
关于iphone - UIView和UIImagView可以同时实现触摸事件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6026647/