Yestay Muratov
Yestay Muratov

Reputation: 1370

check for specific gesture recognizer

I have uipageviewcontroller which contains VCs. As in any pageviewcontroller you can swipe left, right to change VCs. Everytime the animation finish I add gestureRecognizer to it. My question is how to check does view have specific recognizer or not? I need code like this:

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

I am doing it because I have sidebarmenu. When Sidebarmenu appears I want to add gesture for current index pagecontentviewcontroller. So, My code works fine, I just dont want to add gesture everytime the animation finishes.

I am adding code. The problem is my gestures are created in other class(not current). First I am creating the instance of class where I keep gestures:

let transtionManger = TransitionManger()

After I add var of this class which is named exitPanGesture:

pageContentViewController.view.addGestureRecognizer(transtionManger.exitPanGesture3)

The problem is I add it everytime the view appears. I want to check the existence of gesture before adding it. I dont want to add it everytime.

Upvotes: 6

Views: 5425

Answers (2)

user3290180
user3290180

Reputation: 4410

It's not so clear to understand what you want. If you want to keep track of the gesture you put, then you can store a static variable in your view controller and check if it's not nil. This way the gesture will be kept in memory.

Upvotes: 1

Greg
Greg

Reputation: 25459

Is that what you are looking for? Please see comments as 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")
                }
            }
        }

Upvotes: 13

Related Questions