0
votes

I currently have a project set up where for during sign up I am using a UINavigationController to manage the view controllers, and as part of the design I set the UINavigationBar to be transparent with the following code:

    let navBar: UINavigationBar! =  self.navigationController?.navigationBar
    navBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    navBar.shadowImage = UIImage()
    navBar.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
    navBar.tintColor = UIColor.white
    navBar.barTintColor = UIColor.clear

This allows me to use the navigation controller's heirarchy to manage the backwards/forwards movement, and works fine, except that when I show a view controller, any view that I have (set up through Autolayout) does a "jumping" motion to get into its correct position (just like this question's video https://vid.me/9kB5). Some searching led me to try the following 2 solutions

1.) Uncheck Extend Edges - Under Top Bars in my storyboard view controller
2.) Set translucency for the nav bar to false

navBar.isTranslucent = false

This solves the jumping motion and causes the views to be in place when they load, but the problem with this is that the navigation bar now becomes the barTintColor (which for UIColor.clear ends up being black). It seems I am unable to keep both transparency and translucency at the same time. A lot of similar questions on Stack have navigation bars with set colors and not transparent.

The next approach I thought of would be that I would have to get rid of the UINavigationController, and instead implement back buttons on each of my sign up view controllers, but I was hoping to try and tackle this with the navigation controller.

Is it possible to have a UINavigationBar have translucency set to false but maintain transparency?

EDIT: Here's a picture of what the nav bar looks like with the isTransluscent = false code: enter image description here

1

1 Answers

0
votes

Try changing "alpha" property. Make sure that everything you do with navigation bar you do on the main thread.

Solution 2: you can set specific UIImage for your navigation bar background.