Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the UINavigationBar turning black?

Problem:

I have a UITableViewController embedded in a UINavigationController. Pressing a cell in the table view switches to another table view controller. In said table view controller, I'd like for the navigation bar to be invisible while still keeping the tab bar items 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'd like the navigation bar to be normal so in its viewDidAppear() I did the following:

self.navigationController?.navigationBar.isTranslucent = false

Everything is working fine except during the transition (which I am doing via performSegueWithIdentifier) the navigation bar on the first view controller disappears into blackness which looks ugly to be honest. Is there any way to prevent/fix this?

Screenshot: enter image description here

like image 710
cyril Avatar asked Jun 10 '15 18:06

cyril


People also ask

What is isTranslucent?

isTranslucent: A Boolean value indicating whether the navigation bar is translucent (true) or not (false). isOpaque: A Boolean value indicating whether the title is empty and an opaque bezel is set.

How do I change the navigation bar on my Iphone?

Change the Bar Style A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.

What is Scrolledgeappearance?

The appearance settings for the navigation bar when the edge of scrollable content aligns with the edge of the navigation bar. iOS 13.0+ iPadOS 13.0+ Mac Catalyst 13.1+ tvOS 13.0+


1 Answers

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

like image 112
artemchen Avatar answered Sep 22 '22 01:09

artemchen