长按手势识别问题

Long press gesture recognizer issue

在 Interface Builder 中,我向 MKMapView 添加了一个按下手势识别器。

1 秒后发送一个事件(我用它来向地图添加图钉)。我已经检查了我的手势识别器的 "Cancel touches in view" 行为,但我的问题是,一旦长按手势被识别,如果您将手指放在屏幕上并将其拖动到地图视图上,事件(长按) 将在拖动时不断发送,就好像它实际上是一个拖动手势识别器,导致我的地图上添加了几十个图钉...

我该如何解决这个问题?

谢谢。

根据 documentation:

Long-press gestures are continuous. 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). The gesture recognizer transitions to the Change state whenever a finger moves, and it ends (UIGestureRecognizerStateEnded) when any of the fingers are lifted.

突出重点。

我相信您可能没有在手势识别器的委托方法中过滤状态。

您将需要这样的东西:-

- (void)longPressGestureRecognizerStateChanged:(UIGestureRecognizer *)recognizer {
    if (recognizer.state == UIGestureRecognizerStateBegan) {
       // do your stuff...
    }
}