UINavigation Bar to turn transparent as user navigates deeper

700 Views Asked by At

In many apps nowadays it's quite popular that some views (Profile Pages or so) in a NavigationController have a transparent Navigation Bar. You can see what i mean in the mockup. I'm trying to accomplish this effect but I'm having a tough time trying to figure out how to do it. Schema Lets say that I choose an item in a UITableView and I'm getting segued to a UIScrollView. I want the Scroll View to display the return button just like in a normal UINavigationBar but with the difference that the Navigation Bar is invisible. I would like to keep the Navigation Bar logic because it might be possible to dig deeper into the navigation hierarchy from the view with the transparent bar. What would be the best approach to accomplish something like that?

1

There are 1 best solutions below

3
On BEST ANSWER

Add the following to viewDidLoad()

navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true

This will persist to the other views that you push through the navigation hierarchy so make sure you make changes to their viewDidAppear() or load. Or you can take care of this in your current view controller by removing the transparency in the viewWillDisappear().

This will keep the navigation items, which you can change their color as usual.

navigationController?.navigationBar.tintColor = UIColor.lightGray