iphone - 如何在 UIView 中确定手势识别器和触摸的优先级

标签 iphone ios objective-c uiview uigesturerecognizer

来自阅读UIGestureRecognizer Class Reference这意味着 API 将为您处理触摸和手势控制的优先级排序,确保您的 touchesBegan 和相关方法不会在 View 上调用,除非手势识别器首先失败:

A window delivers touch events to a gesture recognizer before it delivers them to the hit-tested view attached to the gesture recognizer. Generally, if a gesture recognizer analyzes the stream of touches in a multi-touch sequence and does not recognize its gesture, the view receives the full complement of touches. If a gesture recognizer recognizes its gesture, the remaining touches for the view are cancelled.

我已经在我的 View 中添加了一个滑动手势,它正在工作。通过一些日志记录,当我进行一次滑动时,该方法会这样报告。然而,我的 touchesBegan 方法通过它的日志报告,尽管 touchesCancelled 方法如预期的那样也收到了一条消息。

我希望并期望手势识别能够防止调用 touchesBegantouchesMoved

所以我的问题是:对于手势识别器来说,实际上是根据其状态延迟触摸,是否需要额外的设置?文档没有提出任何其他必要的建议。

我的设置很简单:

 swipeUpTwoFinger=[[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(doubleSwipeUp:)]autorelease];
swipeUpTwoFinger.direction=UISwipeGestureRecognizerDirectionUp;
swipeUpTwoFinger.numberOfTouchesRequired=2;
[self addGestureRecognizer:swipeUpTwoFinger];

我也尝试过此测试以确保识别器在使用 touchesBegan 处理之前失败(如果您相信上面的文档所说的内容,则此测试不需要是必要的)但 touchesBegan 仍在处理此测试后的日志行:

if (swipeUpTwoFinger.state==UIGestureRecognizerStateFailed)

最佳答案

听起来你需要: swipeUpTwoFinger.delaysTouchesBegan = YES;

关于iphone - 如何在 UIView 中确定手势识别器和触摸的优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15869944/

相关文章:

iphone - 如何制作可在 iOS 5 至 7 上运行的 armv7 arm64 fat 二进制文件?

移动网站上的 Iphone 和 Blackberry 特定宽度问题

iphone - 单击上一个按钮后如何在单选按钮上保持选择

iphone - 在 iPhone 应用程序中存储密码

ios - 是否可以为 ios 应用程序开发转弯导航?

objective-c - iOS CAKeyFrameAnimation 旋转

ios - 界面类似于带有 UIScrollView 的 Snapchat

iphone - 所有程序中的 SIGABRT 和 SIGTERM THREAD

ios - 你如何在 iOS Swift 中执行 "wrap_content"(Android XML 语法)

ios - 从 UITapGestureRecognizer 中排除 subview