Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current touch point and previous touch 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 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];
}

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

like image 751
Uma rajendran Avatar asked Nov 07 '12 12:11

Uma rajendran


1 Answers

If you don't want to store anything you can also do this :

let location = panRecognizer.location(in: self)
let translation = panRecognizer.translation(in: self)
let previousLocation = CGPoint(x: location.x - translation.x, y: location.y - translation.y)
like image 175
Ysix Avatar answered Nov 15 '22 21:11

Ysix