来自阅读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
方法如预期的那样也收到了一条消息。
我希望并期望手势识别能够防止调用 touchesBegan
或 touchesMoved
。
所以我的问题是:对于手势识别器来说,实际上是根据其状态延迟触摸,是否需要额外的设置?文档没有提出任何其他必要的建议。
我的设置很简单:
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/