我想要实现的只是在用户开始手势的点和他结束这样做的点之间划一条线。我认为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] ??? ...
答案 0 :(得分:1)
if(sender.state != UIGestureRecognizerStateEnded){
[self drawLine:_prevDraggingPosition to:currentDraggingPosition];
NSLog(@"???");
}
sender.state != UIGestureRecognizerStateEnded
将成功评估除UIGestureRecognizerStateEnded
之外的每种类型的手势状态。
将!=
更改为==
,它将正常运作。