问题
I want to make a custom side bar by adding a new view to the view controller, the side bar will be in the yellow color background. I want my side bar also to overlap the navigation bar/item (green background color) in my view controller. but the navigation bar/item seems can't be overlapped by my side bar view, it seems only overlap the main view.
I tried to find the answer in stackoverflow, I find this Overlap navigation bar on ios 6 with other view, but the answer is on the Objective-C, I can't read Objective-C :(
What should I do to overlap navigation bar/item ? here is the screenshot of my view controller
I embed the navigation controller like this
回答1:
There are plenty of implementations of slide-over or drawer containers.
What you need to do to get above the navigation bar is CONTAIN the navigation controller inside another view controller.
The stack would look like this.
- MasterViewController
- UINavigationController
- RootViewController
- Menu
- UINavigationController
See this one here:
Swift version of MMDrawerController
回答2:
You can do this by changing your UIViewController
hierarchy. For this you'll need three view controllers. First will contain everything, let's call it MasterViewController
; second—your main content with navigation bar; and third—drawer.
In MasterViewController
instantiate child view controllers and add them to your view controller hierarchy in viewDidLoad()
.
final class MasterViewController: UIViewController {
override func viewDidLoad() {
let drawerViewController = DrawerViewController()
let mainViewController = MainContentViewController()
let navigationController = UINavigationController(rootViewController: mainViewController)
addChildViewController(drawerViewController)
addChildViewController(navigationController)
view.addSubview(navigationController.view)
view.addSubview(drawerViewController.view)
}
}
Now you have navigationController.view
that you can place or animate anywhere within view
.
来源:https://stackoverflow.com/questions/48615295/how-to-overlap-navigation-bar-by-adding-view-in-swift