ios – 检测手指上/下UITapGestureRecognizer

前端之家收集整理的这篇文章主要介绍了ios – 检测手指上/下UITapGestureRecognizer前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何知道手指何时关闭,UITapGestureRecognizer是什么时候?
documentation说我应该只使用UIGestureRecognizerStateEnded作为tap,所以这意味着当手指关闭时,UIGestureRecognizerStateBegin,但我得到的是UIGestureRecognizerStateEnded.
用于注册识别器的代码是:
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]

解决方法

UITapGestureRecognizer是一个离散的手势识别器,因此永远不会转换到开始或改变的状态.来自UIGestureRecognizer类参考:

Discrete gestures transition from Possible to either Recognized
(UIGestureRecognizerStateRecognized) or Failed
(UIGestureRecognizerStateFailed),depending on whether they
successfully interpret the gesture or not. If the gesture recognizer
transitions to Recognized,it sends its action message to its target.

(记住当然UIGestureRecognizerStateRecognized == UIGestureRecognizerStateEnded).

文档说您应该检查点击手势识别器的状态,看看它处于其结束状态,然后再触发代码才能确认它.他们并不是说敲击手势实际上转变到了开始或改变的状态(尽管我承认文档在使用的语言上有点误导).

如果你想检查手指识别器的手指按下事件,我会建议只使用touchesBegan:withEvent :,因为这是你真正的反正.

原文链接:https://www.f2er.com/iOS/329542.html

猜你在找的iOS相关文章