ios – 如何在UIPanGestureRecognizer方法中获取当前触摸点和上一个触摸点?

我是iOS新手,我在我的项目中使用UIPanGestureRecognizer.在我拖动视图时,我需要获取当前触摸点和上一个触摸点.我很难得到这两点.

如果我使用touchesBegan方法而不是使用UIPanGestureRecognizer,我可以通过以下代码得到这两点:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    CGPoint touchPoint = [[touches anyObject] locationInView:self];
    CGPoint prevIoUs=[[touches anyObject]prevIoUsLocationInView:self];
}

我需要在UIPanGestureRecognizer事件触发方法中获得这两点.我怎样才能做到这一点?请指导我.

解决方法

你可以用这个:
CGPoint currentlocation = [recognizer locationInView:self.view];

通过设置当前位置(如果未找到)并每次添加当前位置来存储先前位置.

prevIoUsLocation = [recognizer locationInView:self.view];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...