Search code examples
iosswiftuinavigationcontrolleruinavigationbar

Can navigation bar be anchored to specific location?


Im curious to know if it's possible to anchor the navigationBar to a specific location. I ask because it appears that by default, the navigationBar's top anchor is the statusBar's bottom anchor. But when you hide the statusBar, the navigationBar's top anchor gets relocated to the view's top anchor.

It seems that apple has defaulted some anchoring behaviors to the navigationBar and I was wondering if its possible to customize it.


Solution

  • two cases:

    • if your view controller owns the bar, you can anchor it to anything you like... (e.g. if you use the UINavigationBar as a child of your view)

    • if you dont create it (as in you use the navigation bar that you are provided by being in a navigationController): you cant freely anchor it to something else.