0

Possible Duplicate:
Get swipe direction in Cocoa

In my program I have created a UISwipeGestureRecognizer in a header file and configured its directions to be UISwipeGestureRecognizerDirectionLeft and UISwipeGestureRecognizerDirectionRight in the implementation file. I have set it to call a method called handleSwipe when the gesture is recognized. It successfully calls this method, but when I try to determine the direction of that gesture recognizer using its direction property it does not give me a value. Why so?

Community
  • 1
  • 1
Fitzy
  • 1,871
  • 6
  • 23
  • 40

2 Answers2

2

You cannot use one gesture recognizer to recognize two different gestures. Create two gesture recognizers, one in either direction and point them to handleSwipLeft and handleSwipeRight (that then calls handleSwipe:withDirection: or something).

Hampus Nilsson
  • 6,692
  • 1
  • 25
  • 29
0

I'm not at my computer right now, but you have to compare the locationInView to previousLocationInView to determine direction. I know I used that approach in an earlier app. Today I was adding swipe to some views and took the easier way out of adding two recognizes, one for each direction. The choice is based on how much swipe information you need. In my earlier app I needed to know how hard the user was swiping, so the delta between the two values was needed. In my current app I just need to know that the user has flicked left or right.

tobinjim
  • 1,862
  • 2
  • 19
  • 31
  • My bad: My earlier project used a UIPanGestureRecognizer; a negative velocity meant (IIRC) right to left pan, positive meant left to right. – tobinjim May 10 '12 at 13:18