I have problem with tap gesture. My case is: - A view with UITapGestureRecognizer to dismiss keyboard - A label on view, which has 2 gesture. One UITapGestureRecognizer
to open popup, and UITapGestureRecognizer
(number of touches is 2) to quickly confirm popup.
But when I tap on label, the UITapGestureRecognizer
on view always receive the action. How can I forward action to UILabel
.
Thanks
To get taps on label, you need to enable user interaction for that label
To receive 2 taps you need to do following
In short [tap requireGestureRecognizerToFail:dTap];
will do trick for you making single tap to wait for a while to check if double tap is to happen
UITapGestureRecognizer *dTap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(doubleTapped:)];
dTap.delegate = self;
dTap.numberOfTapsRequired = 2;
dTap.numberOfTouchesRequired = 1;
[label addGestureRecognizer:dTap];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(tapped:)];
tap.delegate = self;
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[label addGestureRecognizer:tap];
[tap requireGestureRecognizerToFail:dTap];
//它在Lable上启用用户交互,默认情况下为NO,因此您必须这样做。
[lbl setUserInteractionEnabled:YES];
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.