Reputation: 2543
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
Upvotes: 6
Views: 11037
Reputation: 9
Adopt the UIGestureRecognizerDelegate
protocol and implement the following method.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (to completely remove gesture recognizers)
return NO;
else
return YES;
}
Upvotes: 0
Reputation: 8075
Looks to me like you're adding the gesture recognizers to the view but removing them from theScrollView. Is this what you intended? You should be removing the gesture recognizers from self.view if you want those to stop.
Upvotes: 0
Reputation: 1356
Why don't you use the below gesture delegate to stop any gesture:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
Upvotes: 1