Why [UIScreen mainScreen].bounds] is not returning full screen size?
You have to add the iPhone 5 Launch image (Default-568h@2x.png
) to your project.
The 568 point tall launch image tells iOS to launch your app in 4" mode. If you don't have this image, your app is treated as a 3.5" app. Even if it is 4" compatible.
UIScreen main bounds does not respect actual device screen size
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/
UIScreen MainScreen Bounds returning wrong size
Apparently, iOS relies solely on the presence of a launch image in the resolution of an iPhone 5+ in order to let the app run in that resolution.
There are two solutions to this problem:
1. Use Asset Catalogs
When you create a new project, there's this thing called an asset catalog which stores your launch image files. Add one of these to your project and presto!
2. Dig out some old files
If you've been around XCode for a while, you'll know that in one of the later versions of XCode 4.x, the app automatically created three default launch image files for your app called Default.png
, Default@2x.png
, and Default-568h@2x.png
. You need these files in your app, which are essentially just black images with the resolutions 480x320
, 960x640
, and 1136x640
, respectively (note that these are in HxW, not WxH).
- Add these files to your "Supporting Files" group
- Go to the project properties and select "Don't Use Asset Catalogs" from the Launch Image section
- Delete the Asset Catalog.
Hopefully this helps someone else who encounters this ridiculous problem.
Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?
Yes, it's orientation-dependent in iOS8, not a bug. You could review session 214 from WWDC 2014 for more info: "View Controller Advancements in iOS 8"
Quote from the presentation:
UIScreen is now interface oriented:
- [UIScreen bounds] now interface-oriented
- [UIScreen applicationFrame] now interface-oriented
- Status bar frame notifications are interface-oriented
- Keyboard frame notifications are interface-oriented
Xcode launch images and full screen issues
This is because Xcode provides placeholders for different devices and respective to them being retina or non retina and device sizes.
As you can see your image is on a placeholder as "unassigned", So xcode cant figure it out which device it is for, hence the image is not showing.
To correct this here is a screenshot --
EDIT
Please migrate to get the launch image assigned to the assets from here
Click on Launch Image Sources -- Use assets catalogue and the pop up will show and then click on migrate.
As you can see in the attribute inspector, you can choose which device launch image you want and it will give you that.
Check by clicking the place holder what image size or resolution it requires and then you just drag and drop those images from finder.
Hope this helps
Edit Final
As it turned out OP was using cMake for the xcode project and by default xcode had already a launch image asset JSON installed which had a wrong configuration, Thus creating another Launch Image wasnt overriding the existing JSON as for cmake the earlier config was being loaded. And by default Universal devices was selected but the Device orientation was totally unchecked.
Checking device orientation after getting a clean version of the project and letting Xcode decide its default Launch Image assets and filling up images in that JSON fixed the issue with OP. Further discussions are mentioned in the link in the comments.
Related Topics
Mfmailcomposeviewcontroller Without Mail App Installed
How to Keep Spritekit Scene Paused When App Becomes Active
Why Does 'Position:Fixed' Not Work When Viewed in an 'Iframe' Using an iPhone or iOS Device
iOS 8 and Xcode 6 Simulator Display Out of Alignment
Xcode Export App, Wildcard Error
Uiwindow? Does Not Have Member Named Bounds
I Get Nil When Using Nsdateformatter in Swift
How to Launch IPA File in iOS 10 Real Device Using Appium 1.6.0
Xcode 13 - "Button" Title Not Disappearing
Using Shader Modifiers to Animate Texture in Scenekit Leads to Jittery Textures Over Time
How to Open Application Using Url
How to Rotate a UIview Without The Black Bars
Does "Let _ = ..." (Let Underscore Equal) Have Any Use in Swift
Cfbundledocumenttype Is Not Working in Myproject-Info.Plist File
Ld: Library Not Found for -Ldoubleconversion React Native 0.59
Uiactivityviewcontroller => Launchservices: Invalidationhandler Called