Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two UITapGestureRecognizer in on 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 if the user tap twice the two methods are called,and i want that if the user make double tap only the first(handleTapGesture) will be called and if he make one tap it will call only the second one(handleTapGesture2)

like image 337
YosiFZ Avatar asked Apr 17 '12 09:04

YosiFZ


2 Answers

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

like image 37
The iOSDev Avatar answered Sep 30 '22 20:09

The iOSDev


use this one..

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];
like image 146
Arun Avatar answered Sep 30 '22 21:09

Arun