Why is the UINavigationBar turning black?

Problem:

I have a UITableViewController built into the UINavigationController . Clicking on a cell in a table view switches to another table view controller. In the specified table view controller, I would like the navigation bar to be invisible while preserving the elements of the tab bar, so I added the following to its viewDidLoad() :

 self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .default) self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.isTranslucent = true self.navigationController?.navigationBar.tintColor = .black 

For the first UITableViewController, I would like the navigation bar to be normal, so in its viewDidAppear() I did the following:

 self.navigationController?.navigationBar.isTranslucent = false 

Everything works fine except during the transition (which I do using performSegueWithIdentifier ) the navigation bar on the first view controller disappears in the dark, which, frankly, looks ugly. Is there any way to prevent / fix this?

Screenshot: enter image description here

+7
source share
3 answers

I recently had a very similar problem. Try setting self.navigationController?.navigationBar.translucent = true both view controllers and self.edgesForExtendedLayout = UIRectEdgeNone .
Storyboard Version: Expanded Edges - Under Top Bands

+4
source

You can animate the transparency of the navigation bar. So, in viewDidLoad for your second UITableViewController you can write the following:

 override func viewDidLoad() { self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default) self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.tintColor = .blackColor() // Play around with the duration until you find // a time interval, you find suitable UIView.animateWithDuration(2) { self.navigationController?.navigationBar.translucent = true } } 
0
source

I recently ran into this again and found a way to fix this in the storyboard. If you use opaque navigation panels, make sure that the option “Under the opaque panels” is set to “Extend edges”. In fact, I just installed all three of them, as shown below:

enter image description here

0
source

Source: https://habr.com/ru/post/988866/


All Articles