Search code examples
iosxcodeswipeangledirection

finding direction and angle of swipe in Xcode


I've just started work on a new game in which the player will fire a projectile by swiping in the direction he needs it to go in. I know how to detect if a swipe is left, right, up, or down using gesture recognizer, but I need to know how to get the angle of the swipe so the projectile can be fired in whatever direction and at whatever angle the player desires.


Solution

  • Sounds like you want to use a UIPanGestureRecognizer instead. Unlike the swipe recognizer, it's called continuously but with different states, so you could do something as simple as just handling the start and end states.

    Docs: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPanGestureRecognizer_Class/index.html