Skip to content

Instantly share code, notes, and snippets.

@kumamotone
Created September 17, 2016 11:53
Show Gist options
  • Save kumamotone/d693b9badf7bc5ac1b62d7bd8bae15d7 to your computer and use it in GitHub Desktop.
Save kumamotone/d693b9badf7bc5ac1b62d7bd8bae15d7 to your computer and use it in GitHub Desktop.
import UIKit
protocol SwipeReturnable {
func addSwipeReturnGesture()
}
extension SwipeReturnable where Self: UIViewController {
func addSwipeReturnGesture() {
let gestureToRight = UISwipeGestureRecognizer(target: self, action: #selector(self.swipeBack))
gestureToRight.direction = .Right
self.view.addGestureRecognizer(gestureToRight)
}
}
extension UIViewController {
@objc private func swipeBack() {
self.navigationController?.popViewControllerAnimated(true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment