取消 iPhone 中 UIBarbutton 上的点击手势
我已将点击手势识别器添加到视图中。我的视图底部有一个图像和一个 UIToolBar,其中有一些 UIBarbuttons 我想取消对这些按钮的任何触摸。我正在尝试使用以下方法来取消触摸。如何检测触摸是否在工具栏或任何栏按钮上?框架也没有为栏按钮定义...
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (gestureRecognizer == tapRecognizer) {
if (touch.view==barbutton/*toolbar or bar button item*/)
{
return NO;
}
}
return YES;
}
I have added Tap Gesture recognizer to a view. My view has an image and a UIToolBar at the bottom with a few UIBarbuttons I want to cancel any touches on these buttons. I am trying to use the following method to cancel the touch. How do I detect whether the touch is on the toolbar or any bar buttons? Frame is also not defined for Bar buttons...
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (gestureRecognizer == tapRecognizer) {
if (touch.view==barbutton/*toolbar or bar button item*/)
{
return NO;
}
}
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是假设工具栏和 self.view 位于同一坐标空间中。如果没有,您必须使用 UIView 的坐标转换方法 (
convertPoint:toView:
) 来使空格匹配。This is assuming the toolbar and
self.view
are in the same coordinate space. If not, you'll have to use UIView's coordinate conversion methods (convertPoint:toView:
) to make the spaces match.按钮是第一响应者,它们的 uitouchup 或其他事件将首先触发,并且不会传播到后备视图。
您可以对按钮进行子类化,并让触摸开始/移动/结束:
让您的后备视图为它们处理所有事件,在这种情况下,您的手势代码应该可以工作。
Buttons are the first responder and their uitouchup or other event will fire first and won't propogate to the backing view.
You can subclass your buttons and have the touchesbegan/moved/ended do:
to have your backing view handle all their events for them in which case your gesture code should work.