2

UIGestureRecognizer参考资料说:“诸如点击或滑动之类的离散事件无法报告手势内的变化”

当手指刚刚触摸屏幕(并且还没有离开它)时,我怎样才能得到通知,然后在它离开屏幕时得到通知?

谢谢你的帮助!

4

2 回答 2

4

您可以通过使用检测触摸

对象答案:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

斯威夫特 3.0 答案:

func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
于 2012-06-13T10:50:31.127 回答
-1

那么你的答案在于你的问题标题,即 UIGestureRecognizerState。您需要在目标方法中检查gestureRecognizer 的状态。像:

- (void)handleTap:(UITapGestureRecognizer *)sender {
           if (sender.state == UIGestureRecognizerStateEnded)     {
                // handling code     
           } 
           else {
                //do anything else
           }

}

这些是可能的枚举:

UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed, 
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded

可能会有所帮助。

于 2012-06-13T12:41:14.237 回答