Xcode 6特定于设备的资产目录 [英] Xcode 6 device-specific asset catalog

查看:98
本文介绍了Xcode 6特定于设备的资产目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为新的6和6+设备更新我的应用。

I'm trying to update my app for the new 6 and 6+ devices.

我为新的iPhone尺寸添加了启动图像(6和6) +)。资产目录中有6和6+的条目。没问题。

I've added launch images for the new iPhone sizes (6 and 6+). There are entries in the asset catalog for both the 6 and 6+. No problem there.

我还有一些我需要添加的全屏视图叠加图像。我已经在@ 2x(iPhone 4s)和R4(iPhone 5 5s 5c)中有这些图像。我以新的分辨率大小创建了图像,但我不确定如何将它们添加到图像集中。

I also have some full-screen view overlay images that I need to add as well. I already have images for these in @2x (iPhone 4s) and R4 (iPhone 5 5s 5c). I've created images at the new resolution sizes, but I'm not sure how to add them into an image set.

当我进入资产目录时,我可以在图像集中选择特定于设备,我看到iPhone,retina-4和iPad的条目。有1x,2x,Retina 4 2x和3x的拖放井。

When I go into the asset catalog, I can choose device-specific in the image set, and I see entries for iPhone, retina-4, and iPad. There are drag/drop wells for 1x, 2x, Retina 4 2x, and 3x.

我的问题 - 我应该在哪里放置iPhone 6的图像?显然3x是6加。我不知道视网膜4井如何用于iPhone 5和iPhone 6,因为屏幕尺寸不同。

My question - where should I put the image for the iPhone 6? Obviously the 3x is for the 6 plus. I don't see how the retina-4 well can be used for both the iPhone 5 and iPhone 6 because the screen sizes are different.

我缺少什么?

推荐答案

我很确定这是Xcode 6中的一个错误。当您从资产目录图像集加载图像时,无论您是缩放还是标准显示模式,您都将获得iPhone 6+的3x条目。对于iPhone 6,您将始终在两种模式下获得2x条目。对于iPhone 4s,您还将获得2x条目。

I'm fairly certain that this is a bug in Xcode 6. When you load an image from an asset catalog image set, you will always get the 3x entry for an iPhone 6+ whether you are zoomed or standard display mode. For an iPhone 6, you will always get the 2x entry in both modes. For an iPhone 4s, you will also get the 2x entry.

所有这些设备都具有不同的缩放比例和宽高比,因此这对于像素精确的图像是不可接受的。我的图像都是全屏的,并且是覆盖的,所以我在缩放模式下看到不正确的位置。

All these devices have different scaling and aspect ratios, so this is not acceptable for pixel-accurate images. My images are all full-screen and meant to be overlays, so I was seeing incorrect placement when in zoomed mode.

我通过创建两个图像集来解决这个问题:

1)iPhone 6 / 6plus在标准模式下

1242x2208图像在3x条目中

750x1334在2x条目中

I worked around this problem by creating two image sets:
1) iPhone 6/6plus in standard mode
1242x2208 image in the 3x entry
750x1334 in the 2x entry

2)iPhone 6 / 6Plus处于缩放模式或iPhone 5

1125x2001 for 3x entry

640x1136用于2x条目

640x1136用于R4-2x条目

2) iPhone 6/6Plus in zoomed mode or iPhone 5
1125x2001 for the 3x entry
640x1136 for the 2x entry
640x1136 for the R4-2x entry

为了使这项工作,我需要确定该设备是否是一个新的,如果它们处于缩放模式。根据这些信息,我从正确的图像集加载图像。

To make this work, I then need to determine if the device is one of the new ones and if they are in zoomed mode. Based on this information, I load the image from the correct image set.

这是我用来确定设备是否是缩放的新设备之一的代码标准模式:

This is the code I use to determine if the device is one of the new ones in zoomed/standard mode:

UIScreen *screen = [UIScreen mainScreen];
if (screen.scale == 3 && screen.currentMode.size.width == 1242 ||
    screen.scale == 2 && screen.currentMode.size.width == 750) {
    self.overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"StdImageSet"]];
} else {
    self.overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ZoomedImageSet"]];
}

这很丑陋,我不想这样做,因为图像集是应该消除这种代码。我没有看到更好的方法,我已经提交了一个雷达(雷达18463463)错误。

This is ugly, and I hate having to do this, since image sets are supposed to eliminate this kind of code. I haven't seen a better way around this, and I've filed a radar (radar 18463463) bug.

这篇关于Xcode 6特定于设备的资产目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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