ios - 检查特定的手势识别器

标签 ios swift uipageviewcontroller gestures

我有一个包含 VC 的 uipageviewcontroller。与在任何 pageviewcontroller 中一样,您可以向左滑动,向右滑动以更改 VC。每次动画完成时,我都会向其中添加 gestureRecognizer。我的问题是如何检查 View 是否有特定的识别器?我需要这样的代码:

if check view has specific recognizer == false {
 add recognizer
}else{
just skip.
}

我这样做是因为我有侧边栏菜单。当 Sidebarmenu 出现时,我想为当前索引页面内容 View Controller 添加手势。所以,我的代码工作正常,我只是不想在每次动画结束时都添加手势。

我正在添加代码。问题是我的手势是在其他类(不是当前类)中创建的。首先,我创建了我保留手势的类实例:

let transtionManger = TransitionManger()

在我添加名为 exitPanGesture 的此类的 var 之后:

pageContentViewController.view.addGestureRecognizer(transtionManger.exitPanGesture3)

问题是每次出现 View 时我都会添加它。我想在添加之前检查手势是否存在。我不想每次都添加它。

最佳答案

这是您要找的吗?请参阅评论作为解释:

// If any gesture recogniser is added to the view (change view to any view you want to test)
      if let recognizers = view.gestureRecognizers {
            for gr in recognizers {
                // This check for UIPanGestureRecognizer but you can check for the one you need
                if let gRecognizer = gr as? UIPanGestureRecognizer {
                    println("Gesture recognizer found")
                }
            }
        }

关于ios - 检查特定的手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30534398/

相关文章:

iOS 8 键盘扩展检测第一响应者变化

ios - 向 ActionSheet 添加按钮时出现 NSInvalidArgumentException

ios - 如何在 iOS 中保存公共(public) .txt 文件(这样任何文本阅读器应用程序都可以打开它)

ios - 在 Swift 中加密密码的最佳方法是什么?

swift - UIPageViewController阶段

ios - 为什么我的设备显示与模拟器不同的自动布局?

swift - 实例化 View Controller 时出错

ios - 网页 View 上的多个图像无法正确滑动

ios - 在 UIPageViewController 内的 ViewController 内的 ScrollView 中检测 ScrollOffset?

由按钮激活的 Swift pageViewController