I am building an iOS app, deployment target 12.1, swift 4.2. The app uses container views and has a navigation bar at the top of the main screens, preferably right under the status bar. In the launchscreen storyboard, I have constrained Navigation Bar.top to Safe.Area.Top. That works fine. But after I set the containerViewController to be the rootViewController in the AppDelegate, the navigation bar as I've constrained it in Main.storyboard (Navigation Bar.top to Safe.Area.Top) appears far below where it should be.
The only way I can get the navigation bar to appear right under the status bar is to create a custom frame for my window in AppDelegate with a negative y-value -- and that is definitely NOT a solution I'm comfortable with.
This seems to generate a y-value too low:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
let containerViewController = ContainerViewController()
window!.rootViewController = containerViewController
window!.makeKeyAndVisible()
return true
}
And this is the egregious hack that gets the navigation bar closer to where it should be:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//window = UIWindow(frame: UIScreen.main.bounds)
let hackedFrame = CGRect(x: 0, y: -44, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
window = UIWindow(frame: hackedFrame)
let containerViewController = ContainerViewController()
window!.rootViewController = containerViewController
window!.makeKeyAndVisible()
//window!.windowLevel = UIWindow.Level.statusBar
return true
}
Screen grabs:
I'm probably missing something really obvious here, but I'd appreciate any help anyone can give.
Thanks.