我的allowableMovement
财产UILongPressGestureRecognizer
似乎被忽略了。我使用 Single View Application 模板创建了一个新项目(Xcode 4.5.1,iOS 6),并在视图中添加了一个长按手势识别器。有一个连接好的插座和一个动作。下面是 action 方法的代码:
- (IBAction)longPress:(UILongPressGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStatePossible) NSLog(@"possible");
if (sender.state == UIGestureRecognizerStateBegan) NSLog(@"began");
if (sender.state == UIGestureRecognizerStateChanged) NSLog(@"changed");
if (sender.state == UIGestureRecognizerStateRecognized) NSLog(@"recognized");
if (sender.state == UIGestureRecognizerStateCancelled) NSLog(@"cancelled");
if (sender.state == UIGestureRecognizerStateFailed) NSLog(@"failed");
CGPoint locationInView = [sender locationInView:self.view];
NSLog(@"long press: allowableMovement= %f, x= %f, y= %f", sender.allowableMovement, locationInView.x, locationInView.y);
}
如果我按下足够长的时间然后放手,我会在日志中得到这个:
2012-10-30 20:24:41.449 Long Press[1078:907] began
2012-10-30 20:24:41.455 Long Press[1078:907] long press: allowableMovement= 10.000000, x= 210.500000, y= 99.500000
2012-10-30 20:24:42.880 Long Press[1078:907] recognized
2012-10-30 20:24:42.882 Long Press[1078:907] long press: allowableMovement= 10.000000, x= 208.500000, y= 96.000000
这是我所期望的。
但无论我设置什么allowableMovement
(正、负、大、小),一旦状态为UIGestureRecognizerStateBegan
,我可以在屏幕上拖动手指。状态更改为UIGestureRecognizerStateChanged
并有频繁更新,并且 locationInView 继续准确跟踪。当我放手时,我得到UIGestureRecognizerStateRecognized
状态和最终输出到日志。
类引用说,如果移动超过 ,识别器应该会失败allowableMovement
。为什么该allowableMovement
属性似乎被忽略了?