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
Why don't you use the below gesture delegate to stop any gesture:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With