当应用程序的部署目标设置为6.0或6.1时,Xcode 6会错误地加载3x图像 [英] Xcode 6 loads 3x image incorrectly when app's Deployment Target is set to 6.0 or 6.1

查看:139
本文介绍了当应用程序的部署目标设置为6.0或6.1时,Xcode 6会错误地加载3x图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在xcode的界面构建器中在storyboard(或xib)中构建UI时遇到此问题。在将图像(在资产目录中具有相同名称)分配给Interface Builder中的图像视图后,xcode在运行ios8的任何非retinahd设备中加载 3x 图像文件而不是2x。

I get this issue when building UI in storyboard (or xib) in xcode's interface builder. After I assign the image (with the same name in asset catalog) to an image view in Interface Builder, the xcode loads 3x image file instead of 2x in any non-retinahd devices which is running ios8.

请注意,此错误仅在应用的部署目标设置为 6.0或6.1 时发生。

Note that this bug only happens when app's deployment target is set to 6.0 or 6.1.

我正在使用资产目录来管理图像资源。

I'm using asset catalog to manage image resources.

此问题已在Xcode 6.0.1和 6.1 GM seed 2 中进行测试和发生。

This issue is tested and happens both in Xcode 6.0.1 and 6.1 GM seed 2.

我搜索了这个问题,很少找到相关主题。所以我想知道是否有人与我有同样的问题,它的最佳解决方法是什么。谢谢。

I googled the issue and could rarely find the related topic. So I wonder if any one gets the same issue with me and what is the best workaround for it. Thank you.

如果有人有兴趣,以下是重现此问题的步骤:

The following is the steps to reproduce this issue in case anyone has the interest:


  1. 安装 Xcode 6

创建iOS项目并设置为使用目标 - c 作为项目语言。

Create an iOS project and set to use objective-c as project language.

将应用的部署目标更改为 6.0或6.1

1x 2x 3x 版本的图片添加到资产目录

Add 1x, 2x and 3x version of an image to the asset catalog.

界面构建器中,将 UIImageView 添加到默认视图控制器默认故事板的视图。

In interface builder, add a UIImageView to the default view controller's view of default storyboard.

界面构建器中,将图像名称设置为资产目录中步骤4中添加的相同图像名称。

In interface builder, set the image's name as the same image name added in step 4 in asset catalog.

选择模拟器为iPhone6(或任何模拟器在 iOS 8.0 上运行,但iPhone6 Plus除外)。

Select the simulator as iPhone6 (or any simulator runs on iOS 8.0 except iPhone6 Plus).

清理项目(产品/清洁)。

运行项目。



更新

正如@Andrei Mankevich在评论中提到的,这个错误似乎在 iOS 8.1 中得到修复。

As @Andrei Mankevich mentioned in the comment, this bug seems to be fixed in iOS 8.1.

我已经使用 Xcode 6.1 GM种子2 中运行 iOS 8.1 的模拟器确认了它(对不起,我不知道)目前没有运行iOS 8.1的真实设备。

And I have confirmed it using the simulator running iOS 8.1 in Xcode 6.1 GM seed 2(sorry I don't have a real device running iOS 8.1 currently).

因为@Andrei Mankevich指出,这个bug可能只存在于iOS 8.0.x中。

So as @Andrei Mankevich pointed out, this bug might only exist in iOS 8.0.x.

推荐答案

经过一番研究后,看起来这个问题确实与iOS有关,所以不太可能通过即将到来的Xcode更新修复。这就是有关资产目录的文档说明:

After some research it looks like this issue is related to iOS indeed and so it isn't likely to be fixed by upcoming Xcode update. That's what documentation says about Asset Catalog:


对于部署目标至少为iOS 7或OS X 10.9的项目,Xcode会将您的资产目录编译为运行时二进制文件格式,以减少你的应用程序的下载时间。

For projects with a deployment target of at least iOS 7 or OS X 10.9, Xcode compiles your asset catalogs into a runtime binary file format that reduces the download time for your app.

因此,当我们使用部署目标时,6.0资源只是以不同的方式存储在IPA文件中。虽然iOS 8.0正确加载编译资源,但它存在加载非编译资源并始终加载3倍密度图像的问题。此问题已在iOS 8.1中修复。

So when we use deployment target 6.0 resources are just stored in different way inside IPA file. While iOS 8.0 is loading compiled resouces correctly, it has the issue with loading non-compiled resources and always loads 3x density images. And this issue was already fixed in iOS 8.1.

至于我们的应用程序中可能的解决方法,我们通过设置xib中每个元素的确切大小并使用<$ c $来修复它c> UIViewContentModeScaleAspectFit contentMode 标志的值。我们使用具有不同分辨率的相同图像资源,因此在缩放后它们看起来也相同。但当然它应该对性能产生负面影响。

As for possible workaround in our app we fixed it by setting exact size of each element in xib and using UIViewContentModeScaleAspectFit value for contentMode flag . We use the same image resources with just different resolution so after scale they also look the same. But of course it should have negative impact on performance.

这篇关于当应用程序的部署目标设置为6.0或6.1时,Xcode 6会错误地加载3x图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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