swift swipe gesture code example
Example 1: swift swipe gesture
override func viewDidLoad() {
super.viewDidLoad()
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:)))
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:)))
leftSwipe.direction = .left
rightSwipe.direction = .right
view.addGestureRecognizer(leftSwipe)
view.addGestureRecognizer(rightSwipe)
}
Example 2: using swipe gesture recognizer swift
@IBAction func swipeHandler(_ gestureRecognizer : UISwipeGestureRecognizer) {
if gestureRecognizer.state == .ended {
// Perform action.
}
}