check for specific gesture recognizer
Asked Answered
V

2

6

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.

Vestiary answered 29/5, 2015 at 16:18 Comment(0)
T
13

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")
                }
            }
        }
Treasurehouse answered 29/5, 2015 at 16:24 Comment(0)
R
1

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.

Rosellaroselle answered 29/5, 2015 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.