swift - UITapGestureRecognizer : Modal View is overlapped by another view

标签 swift modal-dialog gesture overlap

我有一个显示为 modalPresentationStyle = .overCurrentContext 的 UIViewController。

这个上下文 View (self.view) 有 backgroundColor = .clear 和一个名为 content 的 subview 。

content 是全边界宽度和半边界高度,背景为白色。

我已将 UITapGestureRecognizer 添加到 self.view,但我不知道在点击重叠 View (content) 时不要触发点击操作。

关于如何仅在用户点击 View 而不是 subview 时触发操作的想法?

最佳答案

你需要遵循UIGestureRecognizerDelegate,然后实现shouldReceive touch委托(delegate)方法:

extension ViewController: UIGestureRecognizerDelegate {
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        if let touchView = touch.view {
            if touchView.isDescendant(of: view) {
                return false
            }
        }

        return true
    }
}

所以如果触摸区域是subView,那么点击手势将被忽略。

关于swift - UITapGestureRecognizer : Modal View is overlapped by another view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54374633/

相关文章:

Jquery模态插件x关闭按钮部分隐藏

用于状态消息的 JQuery UI 模式对话框直到最后才会更新

iOS 7 禁用向后滑动

ios - CollectionView 单元格最初显得太小,然后跳到正确的大小

ios - DateFormatter 给出不正确的结果

ios - 如何在 iOS 中播放循环视频?

javascript - 将数据传递给 mdDialog

android - Galaxy S4 上的接近传感器(空中手势)

ios - UIGestureRecognizerDelegate 来管理手势——我可以解除触摸分配吗?

ios - 当我在 swift 4 中单击 uitableviewcell 时如何传递数据?