1

I create an empty project (in swift, xcode 8.3) and don't use storyboard, and a navigationcontroller into the window. I don't know why the navigationcontroller is not full screen

in AppDelegate, didFinishLaunchingWithOptions method:


self.window = UIWindow(frame: UIScreen.main.bounds)

let nav = UINavigationController()
nav.view.frame = UIScreen.main.bounds
nav.view.backgroundColor = UIColor.red
self.window?.rootViewController = nav
self.window?.makeKeyAndVisible()

The result is :

enter image description here

chipbk10
  • 5,783
  • 12
  • 49
  • 85
  • Also see http://stackoverflow.com/questions/32641240/ios-9-xcode-7-application-appears-with-black-bars-on-top-and-bottom – rmaddy Mar 10 '17 at 15:33

1 Answers1

22

The reason for the issue is that your project has no launch screen. Add a LaunchScreen.storyboard and configure your project to use it. It doesn't have to have any meaningful content; its mere presence is sufficient to prevent letterboxing which is what you're seeing.

enter image description here

enter image description here

Also, just as a secondary tip:

When you are going to insert a subview into a superview, you are always expressing the subview's frame in terms of the superview's coordinate system. It makes no sense to express it in terms of some other coordinate system as you are doing here.

So, replace

nav.view.frame = UIScreen.main.bounds

with

nav.view.frame = self.window!.bounds

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141