问题
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:
Install Xcode 6
Create an iOS project and set to use objective-c as project language.
Change the app's deployment target to 6.0 or 6.1.
Add 1x, 2x and 3x version of an image to the asset catalog.
In interface builder, add a
UIImageView
to the default view controller's view of default storyboard.In interface builder, set the image's name as the same image name added in step 4 in asset catalog.
Select the simulator as iPhone6 (or any simulator runs on iOS 8.0 except iPhone6 Plus).
Clean the project (Product/Clean).
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.
回答1:
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:
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.
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.
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.
来源:https://stackoverflow.com/questions/26333278/xcode-6-loads-3x-image-incorrectly-when-apps-deployment-target-is-set-to-6-0-or