iOS 按住手势 + 点击 [英] iOS press and hold gesture + tap
问题描述
我有一个按住手势.在按住期间,我想检测屏幕上其他地方的单击.问题是当我开始点击屏幕上的其他地方时,按住手势被中断并且不会调用触摸"功能.有没有办法在点击其他地方时保持按住?
I have a press and hold gesture. During the the press and hold, I'd like to detect single taps elsewhere on the screen. The problem is that when I start tapping elsewhere on the screen the press and hold gesture is interrupted and does not call the "touch up" function. Is there a way to retain the press and hold while tapping elsewhere?
推荐答案
UIKit 提供了多种机制来制作多个 UIGestureRecognizers
在同一个 UIView
上并排工作.哪些以及具体如何取决于根据您的需求和配置.
UIKit provides several mechanisms to make multiple UIGestureRecognizers
on the same UIView
work side by side. Which ones and how exactly depends
on your needs and configuration.
一个是 - (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer
但是,对于您的情况,您必须在您的视图中采用 UIGestureRecognizerDelegate
协议.
However for your case you'll have to adopt UIGestureRecognizerDelegate
protocol in your view.
那么你应该实现 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
方法.
Then you should implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
method.
例如:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
不要忘记让你的 UIView
成为它的 getureRecognizers
的 delegate
.
Don't forget to make your UIView
a delegate
of it's getureRecognizers
.
一些参考:
UIGestureRecognizerDelegate 协议参考
这篇关于iOS 按住手势 + 点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!