Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to completely remove gesture recognizers

I'm trying to remove three gesture recognizers attached to a uiscrollview.

I list them using

NSArray * activeScrollViewGRecs = [theScrollView gestureRecognizers];
NSLog (@"activeScrollViewGRecs count: %d",[activeScrollViewGRecs count]);

I get the three listed.

Then I remove them with:

for (UIGestureRecognizer *recognizer in activeScrollViewGRecs)
{
    NSLog (@"recognizer: %@",recognizer.description);
    recognizer.enabled = NO;
    [theScrollView removeGestureRecognizer:recognizer];
}

Then I list them again, and get a zero count. They should be gone/removed, right ? Why would then the view continue to respond (and gesture methods getting called) to the same touches/swipes. Is there some kind of a "flushing" mechanism that needs to happen before they're gone for good ?

this is how they get created:

tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handle1:)];
tapGesture.cancelsTouchesInView = NO; tapGesture.delaysTouchesEnded = NO; 
tapGesture.numberOfTouchesRequired = 2; tapGesture.numberOfTapsRequired = 2;     
[self.view addGestureRecognizer:tapGesture]; [tapGesture release];

swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handle2:)];
swipeGesture.cancelsTouchesInView = NO; swipeGesture.delaysTouchesEnded = NO; swipeGesture.delegate = self;
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeGesture]; [swipeGesture release];

thanks

like image 926
EarlGrey Avatar asked Mar 02 '12 18:03

EarlGrey


1 Answers

Why don't you use the below gesture delegate to stop any gesture:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
like image 100
cocoakomali Avatar answered Sep 28 '22 08:09

cocoakomali