Check for a specific gesture recognizer

I have a uipageviewcontroller that contains a VC. As with any pageview controller, you can scroll left, the right to change the VC. Every time the animation ends, I add gestureRecognizer to it. My question is how to check if a certain recognizer has a look or not? I need a code:

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

I do this because I have sidebarmenu. When Sidebarmenu appears, I want to add a gesture for the current pagecontentviewcontroller index. So, my code works fine, I just don't want to add a gesture every time the animation ends.

I am adding code. The problem is that my gestures are created in another class (not the current one). First, I create an instance of the class in which I save the gestures:

 let transtionManger = TransitionManger() 

After adding var to this class called exitPanGesture:

 pageContentViewController.view.addGestureRecognizer(transtionManger.exitPanGesture3) 

The problem is that I add it every time a view appears. I want to check for gestures before adding it. I do not want to add it every time.

+6
source share
2 answers

Is this what you are looking for? Please see Comments for an explanation:

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

It’s not so clear to understand what you want. If you want to track the gesture you entered, you can save the static variable in your view controller and check if it is null. Thus, the gesture will be stored in memory.

0
source

Source: https://habr.com/ru/post/988187/


All Articles