Im trying to get a UISwipeGestureRecognizer to work in Swift 3, the default swipe right is working correctly though not up down or left.
I have tried it by control dragging an Action
@IBAction func hole(_ recognizer: UISwipeGestureRecognizer) {
if (recognizer.direction == UISwipeGestureRecognizerDirection.left)
{
print("left")
}else if recognizer.direction == .right {
print("right")
}else {
print("other")
}
}
And, in ViewDidLoad
//gesture recognisers
let swipeRight = UISwipeGestureRecognizer(target: self, action: "holeSwiped:")
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: "holeSwiped:")
swipeLeft.direction = UISwipeGestureRecognizerDirection.left
self.view.addGestureRecognizer(swipeLeft)
to my method
func holeSwiped(gesture: UISwipeGestureRecognizer)
{
if let swipeGesture = gesture as? UISwipeGestureRecognizer{
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.right:
print("right swipe")
case UISwipeGestureRecognizerDirection.left:
print("left swipe")
default:
print("other swipe")
}
}
}
Now, none of the swipes are working except the default right. Any ideas?