检测手指向上/向下UITapGestureRecognizer [英] detecting finger up/down UITapGestureRecognizer

查看:130
本文介绍了检测手指向上/向下UITapGestureRecognizer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何知道手指何时停止以及何时使用 UITapGestureRecognizer

文档说我应该只处理 UIGestureRecognizerStateEnded 作为点击,这意味着当手指关闭时有 UIGestureRecognizerStateBegin ,但我得到的只是 UIGestureRecognizerStateEnded

我用来注册识别器的代码是:

How can I know when the finger is down and when is it up with UITapGestureRecognizer?
The documentation says I should only handle UIGestureRecognizerStateEnded as tap so it means there is UIGestureRecognizerStateBegin when finger is down, but all I get is UIGestureRecognizerStateEnded.
The code I use to register the recognizer is:

[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]


推荐答案

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

UITapGestureRecognizer is a discrete gesture recognizer, and therefore never transitions to the began or changed states. From the UIGestureRecognizer Class Reference:


离散手势从可能转换为已识别
(UIGestureRecognizerStateRecognized)或失败
( UIGestureRecognizerStateFailed),取决于他们是否
成功解释了手势。如果手势识别器
转换为已识别,则会将其操作消息发送到其目标。

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 )。

(Remembering of course that UIGestureRecognizerStateRecognized == UIGestureRecognizerStateEnded).

文档说的是你应该检查一个轻拍手势识别器的状态,看看它是否处于已结束状态,然后再触发你的代码,说它已被识别。他们并不是说轻敲手势实际上会转换到开始或更改的状态(虽然我承认文档在使用的语言中有点误导!)。

The docs are saying that you should check the state of a tap gesture recognizer to see that it is in its ended state, before you fire your code to say that it has been recognized. They are not saying that the tap gesture actually transitions to the began or changed states (although I admit that the docs are a little misleading in the language used!).

如果你想检查一个轻击手势识别器的手指向下事件,我建议只使用 touchesBegan:withEvent:,因为这是你真正想要的事情。

If you want to check for the finger down event for a tap gesture recognizer, I would recommend just using touchesBegan:withEvent:, since this is what you are really after anyway.

这篇关于检测手指向上/向下UITapGestureRecognizer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆