On iPhone5 [[UISCreen mainScreen] bounds].size comes back as 320x480?
Asked Answered
S

2

8

On iPhone5 [[UISCreen mainScreen] bounds].size comes back as 320x480. Why. In all the posts I'm reading, people are saying that it returns the correct screen size. What is going on here? Am I missing something in the .plist file or something?

BTW I am hand coding the GUI, so there is no XIB.

Sylvie answered 5/10, 2012 at 19:21 Comment(6)
Duplicate of #12395700 (and many, many others ...)Yeast
A bit smarmy and not appreciated. Can you point to a specific answer to my question? Because I read every one of those "many, many others" and not one answered the question I asked. Not to say I didn't overlook something, but perhaps you should read my question again before jumping to that conclusion.Sylvie
Definitely incorrect on your claim of a duplicate question. The answer to the link you posted lists simply using mainScreen bounds.Sylvie
If you add a [email protected] launch image to the project (as described in #12395700) and run on on iPhone 5, then [[UIScreen mainScreen] bounds].size returns (width=320, height=568).Yeast
That is bizarre. It also seems really dirty. Is there no programmatic way of getting the software to behave correctly?Sylvie
There is no other way. You can find the same answer multiple times on SO.Yeast
J
30

Unless your app includes a Default-568h.png in it's bundle, it will run inside a 480 point high legacy screen sandbox on the iPhone 5, and can't draw or see any dimensions outside that sandbox.

Note that including this Default-568h.png is only allowed when building an app using Xcode 4.5 and the iOS 6 SDK (or, presumably, later) for submission to Apple's App store.

Added: When building with the iOS 8 SDK (or later) and running the app under iOS 8 (or later), a LaunchScreen.xib will also remove the 480 height sandbox.

Jolinejoliotcurie answered 5/10, 2012 at 22:39 Comment(2)
Note that this sandbox isn't a dirty trick, but helpful in creating an app environment where older apps don't crash or display crazy stuff when the user upgrades to an iPhone 5 that the developer could never have tested their app on at the time it was developed.Jolinejoliotcurie
Dang it I wasted 2 hours of my time on this :(Xeniaxeno
S
1

It would appear that having a launch image in place is a prerequisite to [[UIScreen mainScreen] bounds] working properly on iPhone5. This is an issue for those of us dependent on design teams for our images. It looks like you just have to hack together a launch image and put it in place.

Is there really no better way? Anyone?

Sylvie answered 5/10, 2012 at 21:14 Comment(2)
Default-568h.png is the way, period. This has been discussed at length both on stackoverflow and on Apple's own developer forums. Since Apple only cares about app store distribution, and all app store apps must have launch images, Apple has no need to provide another way to enable the 568 pt screen.Basinet
It does absolutely suck. First of all not having a way to do this from code just seems plain wrong. And secondly it should be perfectly possible to not even use a splash screen. Now I have to integrate a fake "fully black" splash screen just for this to work on one out of the 9 devices targeted. Sheesh. Rant over.Cape

© 2022 - 2024 — McMap. All rights reserved.