4

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.

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.

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. Install Xcode 6

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

  3. Change the app's deployment target to 6.0 or 6.1.

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

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

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

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

  8. Clean the project (Product/Clean).

  9. Run the project.


UPDATE:

As @Andrei Mankevich mentioned in the comment, this bug seems to be fixed in 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).

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

4

1 回答 1

0

经过一些研究,看起来这个问题确实与 iOS 有关,因此不太可能通过即将到来的 Xcode 更新来解决。这就是关于Asset Catalog的文档所说的:

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

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

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

于 2014-10-21T17:29:51.157 回答