I have a pinch gesture recognizer attached to my scrollView (one on top of the default one). I’m trying to enable it and disable it at certain zoom levels but it is not working. I use the commands:
[self.pinchGesture setEnabled:NO];
and
[self.pinchGesture setEnabled:YES];
to enable and disable the pinch gesture. I am trying to debug it and I use this code to print out the description of my gestures:
NSArray *gestures = [self.scrollView gestureRecognizers];
for (UIGestureRecognizer *gesture in gestures) {
NSLog(@"%s, gesture: %@", __FUNCTION__, [gesture description]);
}
I see that for my custom gesture it looks like:
gesture: <UIPinchGestureRecognizer: 0x88a62d0; state = Possible; enabled = NO; view = <UIScrollView 0x880c360>; target= <(action=handlePinch
So even though it is set to enabled = NO, the pinch still calls the handlePinch: method. Is there a reason for this? Or do I need to use the [self.scrollView setGestureRecognizers:<#(NSArray *)#> to remove that pinch gesture? If I am to go with that approach, do I have to loop through my gestures for the scrollView, save references to those, than set those so I don’t set back my custom pinch gesture? Thanks.
The enabled scrollview just does that: enables and disables the scrollview. The Gesture Recognizers are a different animal, that are kind of latched into your scrollview, but behave almost independently. Why not remove the target for the gesture instead of disabling, then add the target back in when enabling? Alternatively, set a boolean that your target method checks and ignores the gesture when the boolean is YES.