我有一个 UITapGestureRecognizer
的 View 。因此,当我点击 View 时,该 View 上方会出现另一个 View 。这个新 View 有三个按钮。当我现在按下这些按钮之一时,我没有得到按钮 Action ,我只得到点击手势 Action 。所以我不能再使用这些按钮了。我该怎么做才能让事件通过这些按钮?奇怪的是按钮仍然突出显示。
我不能在收到点击后删除 UITapGestureRecognizer。因为有了它,新 View 也可以被删除。表示我想要像全屏视频控件这样的行为。
最佳答案
您可以将 Controller 或 View (无论哪个创建手势识别器)设置为 UITapGestureRecognizer
的委托(delegate)。然后在委托(delegate)中你可以实现 -gestureRecognizer:shouldReceiveTouch:
。在您的实现中,您可以测试触摸是否属于您的新 subview ,如果是,则指示手势识别器忽略它。类似于以下内容:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if (self.controlSubview.superview != nil) {
if ([touch.view isDescendantOfView:self.controlSubview]) {
// we touched our control surface
return NO; // ignore the touch
}
}
return YES; // handle the touch
}
https://stackoverflow.com/questions/3344341/
相关文章:
objective-c - 为什么 Objective-C 委托(delegate)通常被赋予属性分
ios - UIImageView 上的 UIGestureRecognizer
objective-c - 最佳实践? - 数组/字典作为核心数据实体属性
objective-c - 如何等待异步调度的 block 完成?
ios - Storyboard 中的 Modal 和 Push segue 有什么区别?
objective-c - 是否可以刷新 UITableView 中的单个 UITableViewC
ios - 在 UITableViewCell 中有一个 UITextField
ios - 如何在 NSAttributedString 中创建可点击链接?