I have three viewControllers in a UINavigationController
. In the second one I need to hide the navigation bar but not the back button and other bar button. For this reason I can't use isNavigationBarHidden = true
Currently I am handling the above as follows :
First viewController :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.barTintColor = Constants.kThemeRedColor
self.navigationController?.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.barStyle = .black
self.navigationController?.navigationBar.isTranslucent = false
}
Second viewController (hide only nav bar) :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = UIColor.clear
}
The issue here is that when I navigate from and to the firstViewController, for a very short duration when the 1st viewController is disappearing and appearing respectively, I see a black nav bar on it. I know this is because of the code written in 2nd viewController. But I don't have any other close solution of doing this. Attaching a screenshot :
First viewController (how it should be) :
Second viewController :
First viewController (with black nav bar for short duration) :