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.
A gesture recognizer decouples the logic for recognizing a sequence of touches (or other input) and acting on that recognition.
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.
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.
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.
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")
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With