How to completely remove gesture recognizers

I am trying to remove three gesture recognizers attached to a uiscrollview.

I list them with

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

I get the three listed.

Then I delete them with

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

Then I listed them again and get a zero number. They need to be removed / removed, right? Why then would the performance continue to react (and the gesture methods invoked) to the same touches / strokes. Is there some kind of flushing mechanism that must happen before they leave forever?

this is how they are 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

+6
source share
3 answers

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

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch; 
+1
source

It looks like you are adding gesture recognizers to the view, but removing them from the ScrollView. Is that what you intended? You must remove the gesture recognizers from self.view if you want them to stop.

0
source

Accept 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; } 
0
source

Source: https://habr.com/ru/post/909848/


All Articles