Two UITapGestureRecognizer Included in a UIView

I want to add to my UIViewController :

 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; tapGesture.numberOfTapsRequired = 2; [self.view addGestureRecognizer:tapGesture]; [tapGesture release]; UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture2:)]; tapGesture2.numberOfTapsRequired = 1; [self.view addGestureRecognizer:tapGesture2]; [tapGesture2 release]; 

the problem is that the user presses two methods twice, and I want that if the user double-clicks only the first one will be called (handleTapGesture), and if he makes one tap, he will only call the second one (handleTapGesture2)

+6
source share
2 answers

use this ...

 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)]; tapGesture.numberOfTapsRequired = 2; [self.view addGestureRecognizer:tapGesture]; [tapGesture release]; UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture2)]; tapGesture2.numberOfTapsRequired = 1; [tapGesture2 requireGestureRecognizerToFail: tapGesture]; [self.view addGestureRecognizer:tapGesture2]; [tapGesture2 release]; 
+10
source

you can use the code i posted on here in this method requireGestureRecognizerToFail: used in viewcontroller.m , this will solve your problem

+1
source

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


All Articles