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

时间:2011-05-17 05:36:37

标签: iphone ios ipad

在UIView中,有几个UIImageView对象的子视图。

因为我需要从UIImageView和UIView的剩余区域检测触摸事件。

我可以同时在UIView和UIImagView中实现触摸事件吗?

感谢。

1 个答案:

答案 0 :(得分:1)

根据您的评论,我认为您应该考虑手势识别器。使用UITapGestureRecognizer识别并响应视图上的点按。

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