在UIView中,有几个UIImageView对象的子视图。
因为我需要从UIImageView和UIView的剩余区域检测触摸事件。
我可以同时在UIView和UIImagView中实现触摸事件吗?
感谢。
答案 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。