user440096
user440096

Reputation:

Find the end/finish coordinates you a UISwipeGestureRecognizer

I can find the start coordinates of where a swipe starts by doing the following

- (void)oneFingerSwipeUp:(UISwipeGestureRecognizer *)recognizer 
{ 
CGPoint point = [recognizer locationInView:[self view]];
NSLog(@"Swipe up - start location: %f,%f", point.x, point.y);
}

Is it possible to find the coordinates where the swipe ended? I looked into the docs and its not mentioned. Is there some work around for this?

Many Thanks, -Code

Upvotes: 2

Views: 1976

Answers (4)

Vyachaslav Gerchicov
Vyachaslav Gerchicov

Reputation: 2457

You need to examine the state property of the gesture recognizer

WARNING

It is incorrect because swipe gesture generates UIGestureRecognizerStateEnded event only.

The only way I found how to solve this issue is to use touchesBegan:. It works for current view only so additionally I should pass touches for example to parent views.

Upvotes: 3

Jakub
Jakub

Reputation: 13860

Yes you can. UISwipeGestureRecognizer is subclass of UIGestureRecognizer. And in there you have method: - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

For more please read this documentation.

Upvotes: 0

wattson12
wattson12

Reputation: 11174

You need to examine the state property of the gesture recogniser

- (void)swipe:(UISwipeGestureRecognizer *)recognizer
{
   CGPoint point = [recognizer locationInView:[recognizer view]];
   if (recognizer.state == UIGestureRecognizerStateBegan)
       NSLog(@"began: %@", NSStringFromCGPoint(point));
   else if (recognizer.state == UIGestureRecognizerStateEnded)
       NSLog(@"ended: %@", NSStringFromCGPoint(point));
}

Upvotes: 7

Deepak
Deepak

Reputation: 1278

CGPoint pt = [recognizer locationOfTouch:0 inView:view];

I believe this will give you the original x,y coordinates of the touch that initiated the gesture.

Upvotes: 0

Related Questions