Why [Uiscreen Mainscreen].Bounds] Is Not Returning Full Screen Size

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).

  1. Add these files to your "Supporting Files" group
  2. Go to the project properties and select "Don't Use Asset Catalogs" from the Launch Image section
  3. 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
Sample Image
Click on Launch Image Sources -- Use assets catalogue and the pop up will show and then click on migrate.

Sample Image

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



Leave a reply



Submit