ios - 具有 UITapGestureRecognizer 的 View 中的 UIButton

标签 ios objective-c iphone cocoa-touch uitapgesturerecognizer

我有一个 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
}

关于ios - 具有 UITapGestureRecognizer 的 View 中的 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3344341/

相关文章:

ios - 有时 ios MKMapView 在转到其他屏幕并返回到 MapScreen 时崩溃

ios - 调整大小后旋转 45 度的图像数据

objective-c - 向我的框架中添加动态库会给我警告

ios - 如何在 iOS 中禁用/启用本地通知?

ios - 选择上方 UITextField 时向下滚动 UIScrollView

iphone - 我应该使用@2x 还是-hd?

Ios标签启用有一些时间延迟

ios appDelegate 窗口 setRootViewController 崩溃

ios - 在 neo4j 支持的 iOS 应用程序上创建节点时分配 UUID

iphone - 使用 UIRefreshControl