Checking the direction of PanGesture in swift might look something like this.
extension UIPanGestureRecognizer {
func isLeft(theViewYouArePassing: UIView) -> Bool {
let detectionLimit: CGFloat = 50
var velocity : CGPoint = velocityInView(theViewYouArePassing)
if velocity.x > detectionLimit {
print("Gesture went right")
return false
} else if velocity.x < -detectionLimit {
print("Gesture went left")
return true
}
}
}
// Then you would call it the way you call extensions
var panGesture : UIPanGestureRecognizer
// and pass the view you are doing the gesture on
panGesture.isLeft(view) // returns true or false
You can also create such a method without extensions, but I think this method is really good.
Hope this helps anyone trying to find the answer to this question.
source
share