问题
There were many articles written and questions asked about iPhone 6 and iPhone 6 Plus screen sizes. This article provides a great explanation.
However, I am confused when testing my app in the simulator.
I have the following code in AppDelegate
.
- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions
{
UIScreen *screen = [UIScreen mainScreen];
NSLog(@"Screen width %.0f px, height %.0f px, scale %.1fx",
(double) screen.bounds.size.width,
(double) screen.bounds.size.height,
(double) screen.scale);
return YES;
}
I get the following results from iOS simulator for various devices:
iPhone 4S: Screen width 320 px, height 480 px, scale 2.0x
iPhone 5: Screen width 320 px, height 568 px, scale 2.0x
iPhone 5S: Screen width 320 px, height 568 px, scale 2.0x
iPhone 6: Screen width 320 px, height 568 px, scale 2.0x
iPhone 6 Plus: Screen width 320 px, height 568 px, scale 2.0x
The results are fine for iPhone 4S, iPhone 5 and iPhone 5S. However, I expect larger screen size for iPhone 6 and iPhone 6 Plus and I also expect scale 3.0 for iPhone 6 Plus. What is wrong?
Thanks for explanation.
回答1:
It seems like you didn't provide correct launch images to your app. When there is no correct launch images set, the app will run like on iPhone 5/5S, that's why you are having these confusing results while logging. iPhone 6 screen size is 375x667 px scale x2, iPhone 6+ 414x736 px scale x3. So, if you want to set launch image for iPhone 6 it should have 750x1334 px size, and 1242x2208 for iPhone 6+ respectively. Good Luck!
EDIT:
As rmaddy mentioned in the comments, it's better to use launch screen storyboard with proper layout constraints to fit all screens, than having bunch of images for all screens(which also increases the app size).
回答2:
You have to add Launch Image in Imageasset for iPhone 6 and 6+ with proper resolution.
if you dont know resolution please check right side navigator > choose 3rd option. right now in screenshot you can see Expected size 1242x2208 pixel
please check attached screenshot. once you add this all images then only you will get proper.
for iPhone 6 it will log
Screen width 375 px, height 667 px, scale 2.0x
for 6+
Screen width 414 px, height 736 px, scale 3.0x
回答3:
Add a Launch Screen to your project, ->File -> New File -> in iOS User Interface -> Launch screen. Then in the General View of your App, select the LaunchScreen.xib in the Launch Screen File field. Try again your code, and you could see the real sizes.
回答4:
In my case, I found the settings in iPhone about the display. (Settings - Display & Brightness - DISPLAY ZOOM).
If your setting is "Zoomed", screen width will be 320px.
回答5:
For others who may come into the question:
Make sure your launch image names are not the same with any other pictures in your project, otherwise Xcode may be confused and also returns iPhone 5 width and height.
来源:https://stackoverflow.com/questions/27268470/iphone-6-plus-screen-size