我想要實現的只是在用戶開始手勢的地方和他結束這一點之間畫出一條線。我認爲UIGestureRecognizerStateEnded是我需要的狀態,但它被多次調用。如果有人能解釋我爲什麼會發生這種情況,以及如何抓住最後一點,我會很感激。爲什麼UIPanGestureRecognizer會多次觸發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年8月5日17:14:46.086 X [2518:356899] --- 2016年8月5日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] ??? ...
什麼是您的日誌輸出,應該清楚它是否多次觸發。目前尚不確定。 – Shubhank
我已更新問題 – AOY
我不確定。也許我只是用一個錯誤的手勢識別器 – AOY