我使用的是UIPinchGestureRecognizer,默认情况下它使用两个手指。如果用户决定执行多任务手势,则还会激活夹点手势操作。
如果检测到四个以上的UITouch实例,是否有一种方法可以取消夹点手势的发生?
编辑删除了示例代码,因为它是错误的方法.
发布于 2013-03-22 15:07:15
由于您没有对UIPinchGestureRecognizer进行子类化,所以不应该使用touchBegan:withEvent:。相反,您应该在发生夹点时调用的方法中处理它。
- (void)handlePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
// if there are 2 fingers being used
if ([pinchGestureRecognizer numberOfTouches] == 2) {
// do stuff
}
}发布于 2014-11-12 11:20:45
使用多任务手势,UIPinchGestureRecognizer返回的UIPinchGestureRecognizer为2,而不是4或5,因为有些触摸会被忽略。
如果事件有4或5次接触,您可以子类UIPinchGestureRecognizer并重写ignoreTouch:forEvent以取消识别器:
- (void) ignoreTouch:(UITouch*)touch forEvent:(UIEvent*)event
{
[super ignoreTouch:touch forEvent:event];
// Cancel recognizer during a multitask gesture
if ([[event allTouches] count] > 3)
{
self.state = UIGestureRecognizerStateCancelled;
}
}https://stackoverflow.com/questions/15553147
复制相似问题