I want to disable the animation when i pop a ViewController with the back button in NavigationController.
I tried:
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(false)
}
But it still animates.
In the Controller that you want to have that button:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .Plain, target: self, action: #selector(backTapped))
}
@objc func backTapped(sender: UIBarButtonItem) {
navigationController?.popViewControllerAnimated(false)
}
Take into account that this way, you will lose the < icon on the back button (since you're overriding that button). However, I think it is not possible to have a custom behaviour and the < icon at the same time (unless you add the < icon as an image by yourself)
In which ViewController you don't want animation,
Add below lines
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIView.setAnimationsEnabled(false)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIView.setAnimationsEnabled(true)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With