Reputation: 4506
When you go press '<' to pop back on your navigation controller previous screen, the screen animates by sliding to the right.
I'd like to change the back behavior so instead of it sliding to the right, it slides to the left instead.
Any ideas how I could achieve this?
Upvotes: 0
Views: 1040
Reputation: 105
You need a custom back button. On your destination view controller create a custom UIButtonItem, set it as your leftBarButtonItem and perform an animation on button's action.
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "back", style: .plain, target: self, action: #selector(self.back))
}
@objc func back(){
//Create and set up the animation
let transition = CATransition()
transition.duration = 0.4
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromRight//animates from right to left
self.navigationController?.view.layer.add(transition, forKey: nil)//adds the animation
self.navigationController?.popViewController(animated: true)
}
Upvotes: 2