iphone - UIView和UIImagView可以同时实现触摸事件吗?

标签 iphone ios ipad

在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/

相关文章:

iphone - 是否有一个库或框架可以使用漂亮的箭头和手写创建注释?

android - OpenGL ES 2.0 的纵向和横向模式

iphone - 如何调整 UILabel 的宽度以适合文本大小?

ios - 当我设置文本并调整自身大小以适应时,会调用哪个 UILabel 方法?

ios - UICollectionView:有没有办法只重新加载补充 View ?

iphone - 查看响应的http header

ios - 蓝牙:如何让 ios 尝试 "App Not Installed"

iphone - 问题在 -[CALayer setBorderColor :]

ios - 原生 iOS 国家/地区选择器

ios - Xcode 9 : how to install ios 10 sdk