gpt4 book ai didi

ios - 为什么 UIPanGestureRecognizer 多次触发 UIGestureRecognizerStateEnded?

转载 作者:行者123 更新时间:2023-11-29 00:44:40 28 4
gpt4 key购买 nike

我想要实现的只是在用户开始手势的点和结束执行此操作的点之间画一条线。我认为 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 之外的每种手势状态。

!= 更改为 == 即可正常工作。

关于ios - 为什么 UIPanGestureRecognizer 多次触发 UIGestureRecognizerStateEnded?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38791652/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com