Disable gesture recognizer
UIGestureRecognizer
has a property named enabled
. This should be good enough to disable your swipes:
swipeGestureRecognizer.enabled = NO;
Edit: For Swift 5
swipeGestureRecognizer.isEnabled = false
Why don't you set the delegate for the swipe gesture recognizer too and handle them within the same delegate method.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ( [gestureRecognizer isMemberOfClass:[UITapGestureRecognizer class]] ) { // Return NO for views that don't support Taps } else if ( [gestureRecognizer isMemberOfClass:[UISwipeGestureRecognizer class]] ) { // Return NO for views that don't support Swipes } return YES;}
I have a similar issue. Some of my disabled users tap and swipe at the same time, so the app moves to the next screen. I set up an option to allow them to use a three-fingered tap instead. I need to invoke the option the popoverControllerDidDismissPopover delegate and when the app first starts. So I wrote a method that combines the answers above. It looks for all of the swipe gesture recognizers and turns them off, then turns on my tap gesture recognizer.
- (void)changeGestureRecognizer { // Three finger tap to move to next screen if ([Globals sharedInstance].useDoubleTapToMoveToNextScreen) { // Let’s see which gestures are active and turn off the swipes for (UIGestureRecognizer *gestureRecognizer in self.view.gestureRecognizers) { NSLog(@"The gestureRecognizer is %@", gestureRecognizer); if ( [gestureRecognizer isMemberOfClass:[UISwipeGestureRecognizer class]] ) gestureRecognizer.enabled = NO; } // Add the three finger tap UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeNext)]; [twoFingerTap setNumberOfTapsRequired:1]; [twoFingerTap setNumberOfTouchesRequired:3]; [self.view addGestureRecognizer:twoFingerTap]; }}