Iphone UIView和UIImagView能否同时实现触摸事件?

Iphone UIView和UIImagView能否同时实现触摸事件?,iphone,ios,ipad,Iphone,Ios,Ipad,在UIView中,有几个UIImageView对象的子视图 因为我需要从UIImageView和UIView的其余区域检测触摸事件 我可以在UIView和UIImagView中同时实现触摸事件吗 根据你的评论,我认为你应该考虑手势识别器。使用UITapGestureRecognitor识别并响应视图上的点击 UITapGestureRecognizer *tapGesture; tapGesture = [[UITapGestureRecognizer alloc] initWithTarge

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

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

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


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

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:(UITapgestureRecognitizer*)手势
-(void)handleTapOnImage:(UITapgestureRecognitizer*)手势
,并在那里处理触摸


还有其他类型的手势。您可以阅读更多有关它们的信息。

您希望在视图和imageView上看到什么样的触摸事件?只需在事件内部进行简单的触摸即可