objective-c - allowableMovement 似乎被忽略了

标签 objective-c ios6 uigesturerecognizer

我的 UILongPressGestureRecognizer 中的 allowableMovement 属性似乎被忽略了。我使用单 View 应用程序模板创建了一个新项目(Xcode 4.5.1,iOS 6)并向 View 添加了一个长按手势识别器。有一个 socket 和一个 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 设置为(positive, negative, big, small),一旦状态为 UIGestureRecognizerStateBegan,我就可以在屏幕上拖动手指.状态变化为UIGestureRecognizerStateChanged,并有频繁的更新,locationInView继续准确跟踪。当我放手时,我得到 UIGestureRecognizerStateRecognized 状态和日志的最终输出。

类引用指出,如果移动超过 allowableMovement,识别器就会失败。为什么 allowableMovement 属性似乎被忽略了?

最佳答案

allowableMovement 属性与手势开始后可以拖动多远无关。这是关于在手势开始之前你可以移动多远。

来自类引用:

The gesture begins (UIGestureRecognizerStateBegan) when the number of allowable fingers (numberOfTouchesRequired) have been pressed for the specified period (minimumPressDuration) and the touches do not move beyond the allowable range of movement (allowableMovement).

当您将 minimumPressDuration 设置为 3 秒之类的高值并将 allowableMovement 设置为 1 像素之类的低值时,这会变得很明显。如果您的手指滚动,手势将不会开始。但是,如果您将 allowableMovement 设置为 100,您的手指可以滚动很多,手势就会开始。

在这种方式下它就像其他属性一样。它们都是关于手势开始所需的内容。

关于objective-c - allowableMovement 似乎被忽略了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13146412/

相关文章:

ios - 选择图像 ios 的不规则部分

ios - Metal 质感不可过滤

iphone - UIActionSheet 高度在 3.5 英寸设备上为 4 英寸

ios - 来自 UIPanGestureRecognizer 的触摸坐标

ios - 单击远程通知后能够重定向到指定 View Controller ,但只有 VC 但没有导航栏

ios - 在ios中的谷歌地图上添加多个图钉

iphone - iPhone应用程序在iOS 4上运行正常,但在iOS 6的启动屏幕上崩溃

iphone - 如何在 UIImageView 上设置 UIGestureRecognizer?

iphone - 输入文本到点击的 UILabel?

ios - presentViewController 使黑屏