我是 iOS 新手,我在我的项目中使用 UIPanGestureRecognizer
。其中我需要在拖动 View 时获取当前触摸点和上一个触摸点。我正在努力获得这两点。
如果我使用 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 - 如何在 UIPanGestureRecognizer 方法中获取当前触摸点和上一个触摸点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13270075/