如何支持2014年各种iphone屏幕尺寸? [英] How to support various iphone screen sizes as of 2014?

查看:133
本文介绍了如何支持2014年各种iphone屏幕尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我差不多完成了构建我的第一个iPhone应用程序,并尝试添加背景图像,并且发现它有点令人困惑,因为现在在不同的iPhone版本中有3个或4个不同大小的屏幕,具有不同的分辨率开机。

I'm almost done building my first iPhone app and am trying to add a background image, and am finding it a little confusing, because nowadays there's like 3 or 4 different size screens among the different iPhone versions, with different resolutions to boot.

所以虽然我知道整个 image@2x.png 的事情,但我仍然不喜欢我知道我真正需要什么。如果我想让我的应用程序在iPhone 4 / 4s,5s / 5c,6/6 +上运行,我需要多少个不同版本的背景图像,以及尺寸和分辨率是多少?

So while I'm aware of the whole image@2x.png thing, I still don't know what I really need. If I want my app to run on iPhone 4/4s, 5s/5c, 6/6+, how many different versions of a background image do I need, and at what sizes and resolutions?

我已经搜索过,并且在2014年之前没有找到任何有凝聚力的答案。

I have googled around and have not found any cohesive answers up to date for 2014.

另外,如果iPhone 6是1334x750 @ 3x,那么这意味着我应该包括4002x2250背景?那么1920x1080 iPhone 6+ @ 3x,5760 x 3240图像?这太棒了!我觉得我必须不正确地理解这一点。

Also, if the iPhone 6 is 1334x750 @3x, does that mean I'm supposed to include a 4002x2250 background? And then for the 1920x1080 iPhone 6+ @3x, a 5760 x 3240 image? That's MASSIVE! I feel like I must be understanding this incorrectly.

推荐答案

如果你想支持原生分辨率iPhone 6 / Plus,您需要添加启动图像(iOS 8之前)或启动屏幕xib(iOS 8)。

If you want to support native resolution of iPhone 6/Plus, you need to add launch images (prior to iOS 8) or launch screen xib (iOS 8).

iPhone 4 / 4S:640 x 960

iPhone 4/4S: 640 x 960

iPhone 5 / 5S:640 x 1136

iPhone 5/5S: 640 x 1136

iPhone 6:750 x 1334

iPhone 6: 750 x 1334

iPhont 6 Plus:1242 x 2208

iPhont 6 Plus: 1242 x 2208

这意味着如果您想支持这些设备,则需要准备4张具有以上分辨率的启动图像。您可以使用iOS模拟器捕获具有不同分辨率的屏幕截图。如果找不到特定分辨率的启动图像,您的应用将在新的分辨率设备上以兼容模式运行。 兼容模式表示您的视图将缩放,以便在仍具有相同逻辑大小时适合新的屏幕大小。

That means you need to prepare 4 launch images with above resolution if you want to support these devices. You can use iOS simulator to capture screenshots with different resolutions. Your app will run in compatibility mode on new resolution devices if it can't find the launch image of the specific resolution. compatibility mode means your view will be scaled to fit the new screen size when still have the same logical size.

编辑:

我认为op误解了 @ 2x @ 3x 是的意思。 iPhone 6的分辨率为 750(像素)x 1334(像素),每英寸326像素。这是 REAL 分辨率。如果支持原生分辨率,则 375(分)x 667(分)是逻辑大小。 iPhone 6 Plus的分辨率为 1242(像素)x 2208(像素),每英寸401像素,逻辑大小为 414(分)x 736(分数)

I think op misunderstands what do @2x and @3x mean. The resolution of iPhone 6 is 750(pixels) x 1334(pixels), 326 pixels per inch. This is the REAL resolution. And 375(points) x 667(points) is the logical size if the native resolution is supported. iPhone 6 Plus's resolution is 1242(pixels) x 2208(pixels), 401 pixels per inch and the logical size is 414(points) x 736(points).

这是具有不同分辨率的图像在iOS设备上的工作方式:

This is how images with different resolutions work on iOS device:

假设你想在iPhone 4s,iPhone 5 / 5S,iPhone 6 / plus上运行你的应用程序。您应该做的第一件事是提供4个启动图像以支持这些设备的原始分辨率。当iOS启动您的应用时,它会检查应用是否提供正确启动图像以支持当前设备的原生分辨率。如果iOS找到它,然后在启动时使用它并且屏幕的逻辑大小为正确,则您的应用正常运行。否则,您的应用将以兼容模式运行,其中所有视图都将被缩放。

Let's say you want to run your app on iPhone 4s, iPhone 5/5S, iPhone 6/plus. First thing you should do is to provide 4 launch images to support native resolutions of these devices. When iOS launch your app, it will check if the app provides the right launch image to support the native resolution of current device. If iOS finds it, then use that in launch time and the logical size of screen is right, your app runs as normal. Otherwise, your app will run in compatibility mode in which all of the views will be scaled.

假设您的应用中有一个名为 foo.png 的图像,其逻辑大小为 100(分)x 100(分)。您希望此图像在上述所有设备中看起来都相同。您应该提供此图像的2个版本。一个是 200(像素)x 200(像素),应命名为 foo.png@2x ,另一个是 300(像素)x 300(像素)名为 foo.png@3x 。如果您使用 [UIImage imageNamed:@foo] 加载此图片,则在iPhone 6 plus以外的设备上,应用程序将加载名为 foo的图像.PNG @ 2倍。否则,应用程序将加载 foo.png@3x 并将其采样至300 * 84%(像素)x 300 * 84%(像素)。

Suppose there is an image named foo.png in your app of which the logical size is 100(points) x 100(points). You want this image looks same in all the above devices. You should provide 2 versions of this image. One is 200(pixels) x 200 (pixels) and should be named foo.png@2x and the other is 300(pixels) x 300(pixels) named foo.png@3x. If you load this image with [UIImage imageNamed:@"foo"], on devices except iPhone 6 plus, the app will load the image named foo.png@2x. Otherwise the app will load foo.png@3x and sample it down to 300 * 84%(pixels) x 300 * 84%(pixels).

如果您从网址加载图片并需要在运行时渲染它。假设你得到的大小是 {width:100,height:100} ,比例是 1.0 。这意味着此图像的 REAL 大小为 100 * 1.0(像素)x 100 * 1.0(像素。如果您不希望它缩放,你需要自己计算逻辑大小。你这样做:

And if you load an image from an url and need to render it on the runtime. Let's say the size you get is {width:100, height:100}, the scale is 1.0. This means the REAL size of this image is 100 * 1.0(pixels) x 100 * 1.0(pixels. If you don't want it to be scaled, you need to calculate the logical size yourself. You do it like this:

UIImage *image = ... // you get it from an url
CGFloat scale = [UIScreen mainScreen].scale;
CGFloat width = image.size.width / scale; 
CGFloat height = image.size.height / scale;
CGRect frame = CGRectMake(50.0f, 50.0f, width, height)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.contentMode = UIViewContentModeCenter;
imageView.image = image;
[self.view addSubview:imageView];

这篇关于如何支持2014年各种iphone屏幕尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆