Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable gesture recognizer

I have two types of recognizer, one for tap and one for swipe

UIGestureRecognizer *recognizer;  //TAP recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(numTap1:)]; [(UITapGestureRecognizer *)recognizer setNumberOfTouchesRequired:1]; [self.view addGestureRecognizer:recognizer]; self.tapRecognizer = (UITapGestureRecognizer *)recognizer; recognizer.delegate = self; [recognizer release];  //SWIPE RIGHT recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)]; self.swipeRightRecognizer =(UISwipeGestureRecognizer *)recognizer; swipeRightRecognizer.direction = UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:swipeRightRecognizer]; self.swipeRightRecognizer = (UISwipeGestureRecognizer *)recognizer; [recognizer release]; 

with this function I can disable taps on some objects.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {  if ((touch.view == loseView) || (touch.view == subBgView) || (touch.view == btnAgain)) {      return NO; }  return YES; } 

How can I disable swipes?

Thanks a lot!

like image 698
Vins Avatar asked May 13 '11 11:05

Vins


2 Answers

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 
like image 145
PeyloW Avatar answered Sep 24 '22 00:09

PeyloW


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; } 
like image 39
Deepak Danduprolu Avatar answered Sep 25 '22 00:09

Deepak Danduprolu