如何告诉UIGestureRecognizer取消现有的触摸? [英] How can I tell a UIGestureRecognizer to cancel an existing touch?

查看:337
本文介绍了如何告诉UIGestureRecognizer取消现有的触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIPanGestureRecognizer 我使用跟踪用户的手指下面的对象( UIImageView )。我只关心X轴上的运动,如果触摸在Y轴上偏离对象框架的上方或下方,我想结束触摸。

I have a UIPanGestureRecognizer I am using to track an object (UIImageView) below a user's finger. I only care about motion on the X axis, and if the touch strays above or below the object's frame on the Y axis I want to end the touch.

得到我需要的一切,以确定触摸是否在对象的Y边界内,但我不知道如何取消触摸事件。翻转识别器的 cancelsTouchesInView 属性似乎不能做我想要的。

I've got everything I need for determining if a touch is within the object's Y bounds, but I don't know how to cancel the touch event. Flipping the recognizer's cancelsTouchesInView property doesn't seem to do what I want.

谢谢! b $ b

推荐答案

这个小技巧对我有用。

@implementation UIGestureRecognizer (Cancel)

- (void)cancel {
    self.enabled = NO;
    self.enabled = YES;
}

@end

c> UIGestureRecognizer @enabled 文档:

From the UIGestureRecognizer @enabled documentation:


禁用手势识别器,因此
未接收到触摸。默认的
值为YES。如果当
手势识别器当前识别
手势时将
属性更改为NO,手势识别器
将转换为取消状态。

Disables a gesture recognizers so it does not receive touches. The default value is YES. If you change this property to NO while a gesture recognizer is currently recognizing a gesture, the gesture recognizer transitions to a cancelled state.

这篇关于如何告诉UIGestureRecognizer取消现有的触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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