为什么 UIPanGestureRecognizer 多次触发 UIGestureRecognizerStateEnded?

Why is UIPanGestureRecognizer firing with UIGestureRecognizerStateEnded multiple times?

我想要实现的只是在用户开始手势的点和他结束手势的点之间画一条线。我认为 UIGestureRecognizerStateEnded 是我需要的状态,但它被多次调用。如果有人能向我解释为什么会发生这种情况以及如何抓住最后一点,我将不胜感激。

- (void)drawingViewDidPan:(UIPanGestureRecognizer*)sender
{
CGPoint currentDraggingPosition = [sender locationInView:_drawingView];

if(sender.state == UIGestureRecognizerStateBegan){
    _prevDraggingPosition = currentDraggingPosition;
    NSLog(@"---");
}

if(sender.state != UIGestureRecognizerStateEnded){
    [self drawLine:_prevDraggingPosition to:currentDraggingPosition];
     NSLog(@"???");
}
_prevDraggingPosition = currentDraggingPosition;
}

日志:

2016-08-05 17:14:46.086 X[2518:356899] --- 2016-08-05 17:14:46.092 X[2518:356899] ??? 2016-08-05 17:14:46.127 X[2518:356899] ??? 2016-08-05 17:14:46.153 X[2518:356899] ??? 2016-08-05 17:14:46.177 X[2518:356899] ??? 2016-08-05 17:14:46.205 X[2518:356899] ??? 2016-08-05 17:14:46.226 X[2518:356899] ??? 2016-08-05 17:14:46.246 X[2518:356899] ??? 2016-08-05 17:14:46.279 X[2518:356899] ??? ...

if(sender.state != UIGestureRecognizerStateEnded){
    [self drawLine:_prevDraggingPosition to:currentDraggingPosition];
     NSLog(@"???");
}

sender.state != UIGestureRecognizerStateEnded 将成功评估除 UIGestureRecognizerStateEnded 之外的每种手势状态。

!=更改为==即可正常使用。