在UIView中,有UIImageView对象的几个子视图。
由于我需要从UIImageView和UIView的其余区域检测触摸事件。
我可以同时在UIView和UIImagView中实现触摸事件吗?
谢谢。
最佳答案
根据您的评论,我认为您应该考虑使用手势识别器。使用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详细了解它们。
关于iphone - UIView和UIImagView可以同时实现触摸事件吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6026647/