UIScreen main bounds does not respect actual device screen size
Asked Answered
J

1

5

I wanted to create a project without any storyboards.

I have deleted the Main and LaunchScreen storyboards.

As usual I added to my applicationDidFinishLaunchingWithOptions:

        window = UIWindow(frame: UIScreen.main.bounds
        window?.rootViewController = ViewController()
        window?.makeKeyAndVisible()

Now in Project Settings -> General if I leave Launch Screen File empty UIScreen.main.bounds is

(CGRect) $R12 = (origin = (x = 0, y = 0), size = (width = 320, height = 480))

And I get the following screen:

enter image description here

Now if I add something to the Launch Screen File field, in Info.plist -> Information Property List a new line with key Launch screen interface file base name appears and the bounds are correct. The bounds are correct even if the value is empty.

Why does the existence of Launch screen interface file base name affect UIScreen bounds?

Jansson answered 29/1, 2019 at 19:0 Comment(0)
M
6

It started in iOS 8.0 when iPhone 6/6plus was released (TheFuquan user commented it started with the iPhone 5 release), in 2014. Back then if you wanted to support such new devices, you would definitely need, as it was required, to add a proper launch screen. Either through static image with different sizes for each devices you support OR through xib/storyboards.

Now, you answered your confusion already. The way to fix that is to provide a proper launch screen/image.

Apple's Human Interface Guidelines (Launch Screen): https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/launch-screen/

Mond answered 29/1, 2019 at 19:10 Comment(3)
Actually it started with the first iPhone 5 going from the height of 480 to 568Sardis
What cracks me is that you don't even need to do provide a proper Launch Screen image. As long as the "Launch screen interface file base name" key exists in Info.plist UIScreen can calculate it's boundsJansson
You either set sets of launch screen images OR provide that "launch screen interface file base name" to the Xcode project settings (or Info.plist, as you've mentioned).Mond

© 2022 - 2024 — McMap. All rights reserved.