Uma rajendran Uma rajendran - 1 year ago 138
Objective-C Question

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

I am new to iOS, I am using

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
method Instead of using
, 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];

I need to get these two points in
event fire method. How can I achieve 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