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: UIBarMetrics.Default) self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.translucent = true self.navigationController?.navigationBar.tintColor = .blackColor()

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

self.navigationController?.navigationBar.translucent = 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: Why is the UINavigationBar turning black?

--------------Solutions-------------

You can animate the translucency of the navigation bar. So in the 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
}
}

Category:ios Time:2018-12-13 Views:2

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.796 (s). 13 q(s)