简体   繁体   中英

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)

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

你可以使用我在这里发布的代码,方法requireGestureRecognizerToFail:用于viewcontroller.m这将解决你的问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM