What you need to do is have the navigation controller be the root view, and add the tab bar controller as it's embedded VC. (The embedded VC is called the root view controller of the navigation controller)
I'm not sure how you are building your view hierarchy but if you wanted to do it
Storyboard
- Drag a Navigation Controller onto the storyboard (from the bottom right search, third tab that looks like a circle with a square in it)
- Delete the default table view that comes up as the embedded VC
- Drag a tab bar controller onto the storyboard
- While holding
control
on your keyboard, drag from the Navigation controller to the tab bar controller.
- Press on the option that says "Relationship segue", root view controller
you now have a tab bar controller embedded into a navigation controller.
Programmatically
Use one of the initializers, for example:
UINavigationController(rootViewController: <UIViewController>)
UINavigationController(navigationBarClass: <AnyClass?>, toolbarClass: <AnyClass?>)
Where the rootViewController is your tab bar controller.
You can use the setViewControllers
method to pass it an array, which could consist of just your tab bar if you didn't use the rootViewController
initializer.
The navigation controller will show a navigation bar at all moments unless you explicitly hide it. You can also subclass navigation bar and navigation controller if you wanted your navigation controller to look different than the default, like it does in the Apple Music app for example.
Edit
So since the question actually seems to be about extending the layout under/over the bars going to paste my comment here:
so just to clarify, the navigation controller is the ENTIRE screen. The bar at the top is known as a Navigation Bar and is accessible via self.navigationController?.navigationBar
.
It doesn't matter what the root view controller is (whether its a tab or not) content will by default go under translucent bars.
Now there are a couple ways to prevent content from going under/over the bars. The easiest is to just do navigationController?.navigationBar.translucent = false
since by default content doesn't go under opaque bars.
Can also do navigationController?.edgesForExtendedLayout = []
Look at extendedLayoutInclludesOpaqueBars
and edgesForExtendedLayout
properties on UINavigationController.