Xcode 6 设备特定的资产目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25954706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:38:45  来源:igfitidea点击:

Xcode 6 device-specific asset catalog

iosiphonexcodeasset-catalog

提问by Kurt Schwartz

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

我正在尝试为新的 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.

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

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.

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

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、Retina-4 和 iPad 的条目。有用于 1x、2x、Retina 4 2x 和 3x 的拖放孔。

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.

我的问题 - 我应该把 iPhone 6 的图像放在哪里?显然 3x 是针对 6 plus 的。我看不出如何在 iPhone 5 和 iPhone 6 上同时使用retina-4,因为屏幕尺寸不同。

What am I missing?

我错过了什么?

回答by Kurt Schwartz

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.

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

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.

所有这些设备都有不同的缩放比例和纵横比,因此这对于像素精确的图像是不可接受的。我的图像都是全屏的并且是叠加的,所以在缩放模式下我看到了错误的位置。

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

我通过创建两个图像集解决了这个问题:
1) iPhone 6/
6plus在标准模式下1242x2208 图像在 3x 条目中
750x1334 在 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

2) 放大模式的 iPhone 6/6Plus 或 iPhone 5
1125x2001 用于 3x 条目
640x1136 用于 2x 条目
640x1136 用于 R4-2x 条目

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"]];
}

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.

这很难看,我讨厌这样做,因为图像集应该消除这种代码。我还没有看到更好的方法来解决这个问题,我已经提交了一个雷达(雷达 18463463)错误。

回答by Anthony Scott

I found this helpful: http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

我发现这很有帮助:http: //www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

Seems the iPhone 6 will use a resampled @2x (iPhone 5) image. Also, the image set's properties (utilities pane) lets you switch between 'Universal' (x1, x2, x3) and 'Device-specific' image wells.

似乎 iPhone 6 将使用重新采样的 @2x (iPhone 5) 图像。此外,图像集的属性(实用程序窗格)允许您在“通用”(x1、x2、x3)和“设备特定”图像井之间切换。

回答by trppr

This is really annoying. For device-specific setting, we would all expect a menu like in LaunchImage Set, different placeholders for different screen sizes.

这真的很烦人。对于特定于设备的设置,我们都希望有一个类似于 LaunchImage Set 的菜单,不同屏幕尺寸的不同占位符。

回答by Julian Król

I place here some of my observations which I did for iPhone devices (maybe someone will find it helpful):

我把我对 iPhone 设备所做的一些观察放在这里(也许有人会发现它有帮助):

  1. iPhone 4S - 2x Any/Anytile
  2. iPhone 5 - 2x 1GB/Anytile
  3. iPhone 5S - 2x 1GB/Anytile
  4. iPhone 6 - 2x 1GB/Anytile
  5. iPhone 6 Plus - 3x 1GB/Anytile
  1. iPhone 4S -2x Any/Any瓷砖
  2. iPhone 5 -2x 1GB/Any瓷砖
  3. iPhone 5S -2x 1GB/Any瓷砖
  4. iPhone 6 -2x 1GB/Any瓷砖
  5. iPhone 6 Plus -3x 1GB/Any瓷砖

To achieve this I checked Devices - iPhone, Memory 1GB. As you can see there is no distinction for graphics between iPhone 5/5S/6. Maybe playing with settings for Metal 1v2/2v2could be distinguish but this looks to me like going too crazy. Knowledge reference starts at 10:50

为此,我检查了设备 - iPhone,内存 1GB。如您所见, 之间的图形没有区别iPhone 5/5S/6。也许玩设置Metal 1v2/2v2可以区分,但这在我看来太疯狂了。知识参考10:50开始

What I got from WWDC right now we should think not resolution/device/device orientation specifics but focus on a size classes (which are the same for iPhones except 6 Plus) but if anyone would still, for some reasons, need that device specific graphics and wants to use asset catalogs (which are great) then here you get what I found available at the moment (Xcode 7).

我现在从 WWDC 得到的,我们不应该考虑分辨率/设备/设备方向的细节,而是关注尺寸等级(除了 6 Plus 之外的 iPhone 是相同的)但是如果有人出于某些原因仍然需要该设备特定的图形并且想要使用资产目录(这很棒),那么在这里您可以获得我目前发现的可用内容(Xcode 7)。

回答by Peng90

Just found a new solution for this issue. Use the retina 4 image for 2x and set the full screen image view's content model to scale aspect fill will get it working on both iPhone 4s and iPhone 6.

刚刚为这个问题找到了一个新的解决方案。使用 2x 的 Retina 4 图像并将全屏图像视图的内容模型设置为缩放比例填充将使其在 iPhone 4s 和 iPhone 6 上都能正常工作。