YosiFZ
YosiFZ

Reputation: 7900

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)

Upvotes: 6

Views: 1752

Answers (2)

Arun
Arun

Reputation: 2281

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];

Upvotes: 10

The iOSDev
The iOSDev

Reputation: 5267

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

Upvotes: 1

Related Questions