Uma rajendran Uma rajendran - 1 year ago 146
iOS Question

How to get current touch point and previous toch point in UIPanGestureRecognizer method

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.

if i use touches began method Instead of using UIPanGestureRecognizer i could get these two points by following code

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

CGPoint touchPoint = [[touches anyObject] locationInView:self];
CGPoint previous=[[touches anyObject]previousLocationInView:self];

Like this i need to get these two points in UIPanGestureRecognizer event fire method. How can i get this please guide me

Answer Source

You can use this:

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]; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download