Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 检查特定手势识别器_Ios_Swift_Uipageviewcontroller_Gestures - Fatal编程技术网

Ios 检查特定手势识别器

Ios 检查特定手势识别器,ios,swift,uipageviewcontroller,gestures,Ios,Swift,Uipageviewcontroller,Gestures,我有一个包含VCs的uipageviewcontroller。就像在任何pageviewcontroller中一样,您可以向左、向右滑动以更改VCs。每次动画完成时,我都会向其添加手势识别器。我的问题是如何检查视图是否具有特定的识别器?我需要这样的代码: if check view has specific recognizer == false { add recognizer }else{ just skip. } 我这样做是因为我有侧边栏菜单。当出现侧边栏菜单时,我想为当前索引页面Co

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

if check view has specific recognizer == false {
 add recognizer
}else{
just skip.
}
我这样做是因为我有侧边栏菜单。当出现侧边栏菜单时,我想为当前索引页面ContentViewController添加手势。所以,我的代码工作得很好,我只是不想每次动画结束时都添加手势

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

let transtionManger = TransitionManger()
在我添加了这个名为exitPanGesture的类的var之后:

pageContentViewController.view.addGestureRecognizer(transtionManger.exitPanGesture3)

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

这就是你要找的吗?请参见注释作为解释:

// 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")
                }
            }
        }

不太清楚你想要什么。如果要跟踪放置的手势,可以在视图控制器中存储一个静态变量,并检查它是否为零。 这样,这个手势将被保存在记忆中