В Swift вы можете выполнить это с помощью кода, подобного следующему:
// First declare and initialize each swipe gesture you want to create. I have added swipe left and right, to go back and forth between views.
let rightSwipe : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(sender:)))
rightSwipe.direction = .right
let leftSwipe : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(sender:)))
leftSwipe.direction = .left
Далее вы хотите обработать каждый удар внутри функции.
@objc func handleSwipe(sender: UISwipeGestureRecognizer) {
if sender.direction == .right { // user swiped right
// push view controller (push new view on the navigation stack)
self.navigationController?.pushViewController(viewController(), animated: true)
} else { // user swiped left
// pop view controller (go back one view on the navigation stack)
self.navigationController?.popViewController(animated: true)
}
}