1

Through swipe gesture, is it possible to calculate the distance of swipe (up, down, left, right)?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174

2 Answers2

1
- (CGFloat)distanceBetweenTwoPoints:(CGPoint)fromPoint toPoint:(CGPoint)toPoint

{
float x = toPoint.x - fromPoint.x;
float y = toPoint.y - fromPoint.y;
return sqrt(x * x + y * y);
}

Hope its help you, just pass starting and endpoint to this method ....

Matt
  • 74,352
  • 26
  • 153
  • 180
GhostRider
  • 1,197
  • 10
  • 19
0

I've used an approach similar to this article to recognise swipe gestures of a certain number of pixels, but if you're using a base SDK of at least 4 try using UISwipeGestureRecognizer which can make it much easier; see this post.

Community
  • 1
  • 1
petert
  • 6,672
  • 3
  • 38
  • 46
  • have a play around with this example: http://developer.apple.com/library/ios/#samplecode/SimpleGestureRecognizers/Listings/Classes_GestureRecognizerViewController_m.html#//apple_ref/doc/uid/DTS40009460-Classes_GestureRecognizerViewController_m-DontLinkElementID_4 - looks like you can use the view? – petert Jan 10 '11 at 09:40
  • I do this code two day ago , its tell in which side you swipe and me just try to show grid style view for images – GhostRider Jan 10 '11 at 10:28