取消 iPhone 中 UIBarbutton 上的点击手势

发布于 2024-10-14 12:09:45 字数 424 浏览 6 评论 0原文

我已将点击手势识别器添加到视图中。我的视图底部有一个图像和一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

◇流星雨 2024-10-21 12:09:45
CGPoint location = [touch locationInView:self.view];
if(CGRectContainsPoint(toolbar.frame, location)) { ... }

这是假设工具栏和 self.view 位于同一坐标空间中。如果没有,您必须使用 UIView 的坐标转换方法 (convertPoint:toView:) 来使空格匹配。

CGPoint location = [touch locationInView:self.view];
if(CGRectContainsPoint(toolbar.frame, location)) { ... }

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.

酷到爆炸 2024-10-21 12:09:45

按钮是第一响应者,它们的 uitouchup 或其他事件将首先触发,并且不会传播到后备视图。

您可以对按钮进行子类化,并让触摸开始/移动/结束:

[self.nextResponder touchesBegan:touches withEvent:event];

让您的后备视图为它们处理所有事件,在这种情况下,您的手势代码应该可以工作。

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:

[self.nextResponder touchesBegan:touches withEvent:event];

to have your backing view handle all their events for them in which case your gesture code should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文