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

标签 ios objective-c uipangesturerecognizer uitouch touchesbegan

我是 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/

相关文章:

ios - 在同一个 View Controller Objective C 中为多个 UIPickerViews 设置唯一的默认值

ios - 使用 UIPanGestureRecogniser 限制 View 移动

swift - UIPan识别器 : Cant present AlertController

ios - 如何通过调用方法设置导航栏颜色?

ios - 将 pdf 文档保存到 iOS 文件应用程序时如何指定文件名?

ios - TextLabel 在 ScrollView 中被截断

ios - UIView 的 subview 何时/何处从 Storyboard初始化?

ios - 如何快速将 Carbon Kit 添加到我的项目中?

ios - 如果平移,UIButton 框架不会改变

ios - 如何克服 UITableViewCell 子类限制