UIScreen.mainScreen is the same size on all devices [duplicate] - ios

This question already has an answer here:
App not sized properly iOS 8 iPhone simulator
(1 answer)
Closed 8 years ago.
I have a weird issue which suddenly appeared. The problem is that my app seems to be scaling my views, when changing device from iPhone 6 to iPhone 6 Plus for instance. So if I have a title with a certain font size the same title with take up the same amount of space on the iPhone 6 Plus screen when all I want is for the size to be the same and just appear smaller on the larger device. Do anyone know how this happened and how to fix this?
I noticed by running:
NSLog(#"%f", [UIScreen mainScreen].bounds.size.width);
NSLog(#"%f", [UIScreen mainScreen].bounds.size.height);
That his generates the same output on all simulator devices:
320
568
I would expect it to be something different on the larger devices. Does this have anything to do with it?

Did you add launch images for the iPhone 6 and 6 Plus devices? Otherwise it will run scaled in these resolutions (and the [[UIScreen mainScreen] bounds] call will return the bounds as if running in a 4-inch device).

Just add a new default png photo with 1136 height.
[[UIScreen mainScreen] bounds].size
will return new height of 4-inch screen.

It is 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

You could still work around to get the different values. Here is the code:
+ (CGRect)screenBoundsFixedToPortraitOrientation {
UIScreen *screen = [UIScreen mainScreen];
if ([screen respondsToSelector:#selector(fixedCoordinateSpace)]) {
return [screen.coordinateSpace convertRect:screen.bounds toCoordinateSpace:screen.fixedCoordinateSpace];
}
return screen.bounds;
}

Related

UIScreen mainScreen bounds returns iPad 2's bounds on iPad Air 2

I've just restarted work on a project I last worked on 4 years ago. Back then, I was using Xcode 3.2 and an iPad 2. Now I am on Xcode 8.1 and an iPad Air 2.
I can build and run the project just fine with Xcode 8.1 but there is something strange going on when getting the screen size using
CGRect rect = [[UIScreen mainScreen] bounds];
It returns 768x1024 pixels on my iPad Air 2 which can't be true because the iPad Air 2's native resolution is 1536x2048. 768x1024 is the resolution of the iPad 2, my old device.
Furthermore, not only does bounds return the wrong dimensions, I can also clearly see that the graphics I draw to my view have been upscaled.
So my assumption is that my project is running in some sort of legacy/compatibility mode that tries to make the app believe it is still running on an iPad 2 in a resolution of 768x1024 instead of a resolution twice as big. Could that be the case or what is the explanation for this phenomenon?
So how can I get this to work correctly? i.e. how can I get bounds to return 1536x2048 and stop automatic upscaling? I have already looked through the various options in Xcode but I don't see anything that could explain the behaviour I'm seeing here. My deployment target is set to iOS 10.1 so I don't really see why my app is put in this strange legacy mode or whatever it is...
You are confused here you are getting correct bounds from here
CGRect rect = [[UIScreen mainScreen] bounds];
1536x2048 is the resolution of iPad Air 2 not its screen size i.e. iPad Air 2 is supporting #2x resolution.
If you will check bounds of iPad Air 2 then you will get 768x1024

swift ios check for iphone 5 or iphone 6 using size class portrait mode

I wonder if its possible to check if the user is using an iphone 5 or iphone 6 using size class?
I have a header image that I want to make larger when the user is using an iphone 6 instead of iphone 5.
Right now I am using this library to check what device.
And I do so by adding this in viewDidLoad
if device == .iPhone5 || device == .iPhone5s || device == .iPhone5c {
//Update image size constraints etc
view.layoutIfNeeded()
}
But is it possible to use size class only?
Only iphone 6 plus has different size class (regular class at landscape). You can't distinguish between iphone 5 and 6 using size class.
You can use viewWillTransitionToSize and check screen size to determine the device. Alternatively, you can use the following variables:
[[UIScreen mainScreen] bounds].size.height
[[UIScreen mainScreen] bounds].size.width
(SOURCE)
In instances where two devices with equal screen sizes but different resolutions exist, the scaling factor of resolution could be used to discern which device you're dealing with. (DOCS)
float scaleFactor = [[UIScreen mainScreen] scale];

Why in XCode 7 iPhone 6 plus simulator's [UIScreen mainScreen] size and scale return different value with real devce?

After upgrading to xcode 7, I found a strange problem. When I call [[UIScreen mainScreen] scale] on iPhone6+ simulator, it returns 3.0, but it returns 2.0 on iPhone 6+ real device.
Is this a bug or it will also return 3.0 on iPhone 6s+ real device? since I haven't got the real iPhone 6s+, cannot test it yet.
PS. If I don't set "App Icons and Launch Images"->"Launch Screen File", [[UIScreen mainScreen] bounds].size will return 320x480, but if set "Launch Screen File", it will return 414x736, is there any documents for this problem?
Take a look at my note https://github.com/onmyway133/blog/issues/59
See this for a whole list of devices and their scale factors https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
The iPhone 6 and 6+ introduced display mode https://www.cnet.com/how-to/explaining-display-zoom-on-iphone-6-and-6-plus/
You can see that currently the iPhone 6+, 6s+, 7+ phones have scale factor of 2.88 in zoomed mode, and 2.6 in standard mode
You can also see that in zoomed mode, iPhone 6 has the same logical size as the iPhone 5

How to detect if ios8 custom keyboard extension is running in not iphone 6 optimized app?

In the app that not optimized for iphone 6 in standard display mode keyboard and status bar shows zoomed. This causes my manually layouted custom keyboard extension to show streched. How can I detect this zooming to fix layout?
Use self.view.frame.size.width It returns 320 for zoomed mode & 414 for regular mode on my 6+ (hopefully on 6 also) in - (void)updateViewConstraints
Eventually you will not need to do this as whatsapp and other apps get updated (I believe whatsapp just did) but how I get around it temporarily is by getting the size of the view where I am drawing my keyboard view.
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
The iPhone 6 and 6+ will tell you that your screen width 320 for portrait and 568 landscape like an iPhone 5. You can then use the same drawing you do for the iPhone 5.
When the app is optimized for the iPhone 6 and 6+ you will get their real measurements.
Something I don't get is why people are downvoting my answer when it is the right one. We had to specifically deal with this problem. When the app where your extension runs is not optimized for iPhone 6 the dimensions are the same as the previous iPhone and the app is scaled up to full screen. Just run in an iPhone 6 an old app that was never updated and see it for yourself.

Wrong screen size returned for iPhone 5 simulator [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How iPhone 5 + iOS6 will decide if an app must be run in letterbox mode
I'm using:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
to get screen size.
The returned value is {0,0, 320, 480} for iPhone 5 on iOS simulator. Because of this my OpenGL viewport is smaller than the screen and I have 2 black stripes. I can't try at this moment the code on device.
Is there some workaround to get correct screen size?
I must mention that I'm using same project for several years(since iPhone 3G).
You need to add Default-568h#2x.png in project.

Resources