Disable GestureRecognizer
At swift4,
Well in case of many gestures on many views you can enable and disable a gesture like this.
Lets say we have UIView array and we want to disable a gesture which is the first gesture added to the first view in view array named as ourView.
ourView[0].gestureRecognizers![0].isEnabled = false
Also you can enable or disable all the gestures at the same time like this.
for k in 0..<ourView.count {
for l in 0..<outView[k].gestureRecognizers.count {
ourView[k].gestureRecognizers![l].isEnabled = false
}
}
gestureRecognizers
is an array that contains all gesture recognizers attached to the view. You should loop through all gesture recognizers in that array and set their enabled
property to false like this:
for (UIGestureRecognizer * g in imageViewGurka1.gestureRecognizers) {
g.enabled = NO;
}
Swift 5
Below the equivalent for Swift 5
for gesture in imageViewGurka1.gestureRecognizers! {
gesture.isEnabled = false
}
Storyboard/Outlet Solution
Background: I had a UIView that I wanted to act like a button so I added a tap gesture recognizer to it. When a user taps the 'button' I wanted to disable the button, perform some animation, and re-enable the button after the animation.
Solution: If you're using storyboards and you added a gesture recognizer to a UIView, control+drag from the gesture recognizer into the assistant editor to create an outlet. Then you can set gestureRecognizerName.isEnabled = false
.
@IBOutlet var customButtonGestureRecognizer: UITapGestureRecognizer!
@IBAction func didTapCustomButton(_ sender: Any) {
customButtonGestureRecognizer.isEnabled = false
performSomeAnimation(completionHandler: {
self.customButtonGestureRecognizer.isEnabled = true
})
}