Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 274
Yestay Muratov Avatar asked May 29 '15 16:05

Yestay Muratov


People also ask

What is UIGestureRecognizer?

A gesture recognizer decouples the logic for recognizing a sequence of touches (or other input) and acting on that recognition.

What is UITapGestureRecognizer Swift?

UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer . For gesture recognition, the specified number of fingers must tap the view a specified number of times. Although taps are discrete gestures, they're discrete for each state of the gesture recognizer.

How to use tap gesture recognizer Swift?

Adding a Tap Gesture Recognizer in Interface Builder You don't need to switch between the code editor and Interface Builder. Open Main. storyboard and drag a tap gesture recognizer from the Object Library and drop it onto the view we added earlier. The tap gesture recognizer appears in the Document Outline on the left.

Which of the following is an Apple provided base class for recognizing multitouch input gestures?

The UIResponder class provides methods to recognize and handle the mouse events that occur when the user taps or drags on the iPhone's screen.


2 Answers

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")
                }
            }
        }
like image 158
Greg Avatar answered Sep 30 '22 19:09

Greg


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.

like image 36
user3290180 Avatar answered Sep 30 '22 21:09

user3290180