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.
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)
Just Use this on the viewcontroller you have to pop
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(false)
UIView.setAnimationsEnabled(false)
}
Or
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(false)
UIView.setAnimationsEnabled(false)
}
Animation for view is totally removed. And After poped don't forget to add UIView.setAnimationsEnabled(true) on your next viewcontroller.
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)
}
viewWillDisappear() doesnt handle the animation, its just.
If you're using a UINavigationController
self.navigationController?.popViewController(animated: false)
If you're just using UIViewController
self.dismissViewControllerAnimated(false, completion: nil)
If you want to custom animation maybe try this:
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.tintColor = UIColor.white
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "◁", style: .plain, target: self, action: #selector(backTapped(sender:)))
}
// with fade animations
@objc func backTapped(sender: UIBarButtonItem) {
let transition: CATransition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn)
transition.type = CATransitionType.fade
self.navigationController!.view.layer.add(transition, forKey: nil)
navigationController?.popViewController(animated: false)
}
// "◁" added this way: Edit -> Emoji & Symbols
You can try this
override func viewWillDisappear(animated: Bool) {
self.navigationController?popViewControllerAnimated(false)
}