I have a UINavigationcontroller with following set in rootviewcontroller or first controller
override func viewDidLoad() {
super.viewDidLoad()
self.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationBar.shadowImage = UIImage()
}
The reason is I don't want UINaviationBar to be shown.
Now I am pushing another viewcontroller into the stack and I want to have UINavigationBar in the second controller and using below code to achieve this
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController!.navigationBar.setBackgroundImage(UIImage(named:"mainhead.png"), for: UIBarMetrics.default)
}
Now popping second controller to first and using below code in second controller viewWillDisappear to hide the UINavigationBar
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
}
Above logic works but the transition is not smooth. I am able to see the UINavigationBar until first viewcontroller appears and then the UINavigationbar disappears
How do I make the transition smooth? I can hide and unhide but I am wondering what is the right way of doing this
Thanks