[英]Many tap gesture in on view
I have problem with tap gesture. 我的点击手势有问题。 My case is: - A view with UITapGestureRecognizer to dismiss keyboard - A label on view, which has 2 gesture.
我的情况是:-使用UITapGestureRecognizer消除键盘视图-视图上的标签具有2个手势。 One
UITapGestureRecognizer
to open popup, and UITapGestureRecognizer
(number of touches is 2) to quickly confirm popup. 一个
UITapGestureRecognizer
打开弹出式窗口,并UITapGestureRecognizer
(触摸次数为2),以快速确认弹出。
But when I tap on label, the UITapGestureRecognizer
on view always receive the action. 但是,当我点击标签时,视图上的
UITapGestureRecognizer
始终会收到操作。 How can I forward action to UILabel
. 如何将操作转发到
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 要接收2次点击,您需要执行以下操作
In short [tap requireGestureRecognizerToFail:dTap];
简而言之
[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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.