ios - 如何缩短 "delayTouchesBegan"delays touchesBegan 的时间?

标签 ios iphone objective-c uitapgesturerecognizer touchesbegan

在我的一个 View Controller 中,我有几个包含 UITapGestureRecognizer 的 View ,以及 touchesBegan 的实现。我需要优先于 touchesBegan 进行点击,因此我将手势识别器的 delaysTouchesBegan 属性设置为 YES。这可以正常工作,但存在一个问题:手势识别器延迟 touchesBegan 的时间过长。根据documentation :

When the value of the property is YES, the window suspends delivery of touch objects in the UITouchPhaseBegan phase to the view. If the gesture recognizer subsequently recognizes its gesture, these touch objects are discarded. If the gesture recognizer, however, does not recognize its gesture, the window delivers these objects to the view in a touchesBegan:withEvent: message (and possibly a follow-up touchesMoved:withEvent: message to inform it of the touches’ current locations).

问题基本上是,当手势识别器无法识别手势并将这些对象传送到 touchesBegan 时,该操作花费的时间太长。有没有办法加快它的速度,或者只是确定它是否是点击的手势处理是密集的并且不可能缩短?


编辑:

这里有更多信息。这是我用来设置手势识别器的代码:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.cancelsTouchesInView = NO;
tapRecognizer.delaysTouchesBegan = YES;
tapRecognizer.delegate = self;
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;
[self.someView addGestureRecognizer:tapRecognizer];

最佳答案

我会通过将 UITapGestureRecognizer 更改为 UILongPressGestureRecognizer 来解决它。这两个的标题有点误导,但使用 UILongPressGestureRecognizer 您可以设置 minimumPressDuration:

The minimum period fingers must press on the view for the gesture to be recognized.

UILongPressGestureRecognizer *tapRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.delegate = self;
tapRecognizer.minimumPressDuration = //Up to you;
[self.someView addGestureRecognizer:tapRecognizer];

关于ios - 如何缩短 "delayTouchesBegan"delays touchesBegan 的时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20627715/

相关文章:

ios - Swift 提取正则表达式匹配

ios - UIScrollView 内的 UIStackView : how to center-align stack view/items?

ios - 如何修复 ipad 中的方向错误?

c# - 查询sql数据库

ios - 如何获取 iOS5 map 中 2 个引脚之间的逐向方向?

ios - 解析 CloudKit 错误(CKError)

php - 如何区分 HTTP 请求与 PHP 中的 Web 浏览器或移动设备(应用程序)?

iphone - 调用类别方法时发送到实例的无法识别的选择器

iphone - 使用 OpenAl 混合声音

iphone - 使用 REST api 后端开发 iOS 应用程序(基于数据库)