UIPangestureRecognizer

UIPangestureRecognizer

本文介绍了如何在UIPanGestureRecognizer方法中获取当前触摸点和上一个触摸点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to iOS, I am using UIPanGestureRecognizer in my project. In which I have a requirement to get current touch point and previous touch point when I am dragging the view. I am struggling to get these two points.

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

If I use touchesBegan method Instead of using UIPanGestureRecognizer, I could get these two points by the following code:

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

我需要在 UIPanGestureRecognizer中获得这两点/ code>事件火灾方法。我怎样才能做到这一点?请指导我。

I need to get these two points in UIPanGestureRecognizer event fire method. How can I achieve this? please guide me.

推荐答案

你可以使用这个:

CGPoint currentlocation = [recognizer locationInView:self.view];

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

Store previous location by setting current location if not found and adding current location everytime.

previousLocation = [recognizer locationInView:self.view];

这篇关于如何在UIPanGestureRecognizer方法中获取当前触摸点和上一个触摸点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 13:49