Running an iOS7 project under Xcode 6 - Image asse

2019-02-03 10:51发布

问题:

I'm trying to run an iOS7 project under Xcode6 on an iOS7 device. At first all seemed to be A-OK, but then I noticed that all images that reside in Images.xcassets don't show up at runtime.

I can see then correctly in design (storyboard), and I see them if I run the app in the simulator.

Anyone having an idea how to fix this? Thanks!

NOTE: the project runs fine on Xcode5.x therefore it's not the usual culprit (mismatch in the image name "casing").

ADDITIONAL NOTE: I've just tried with another iOS7 project: same problem...

ADDITIONAL NOTE: I've tried using image assets in a brand new project created under Xcode and... images show up.

回答1:

Something I found in the Xcode 6 Beta Release Notes:

Images from asset catalogs in projects with a minimum deployment target of iOS 7 or OS X 10.9 will be available when running on iOS 8 and OS X 10.10, but not iOS 7 and OS X 10.9.(17029658)



回答2:

I had the same problem, I have noticed that if I move my images from Images.xcassets to the "Supporting Files" folder, the images show up on iOS7. I Hope this helps



回答3:

I suddenly add jpg image to Image Assets. When resaved in png, all work OK



回答4:

Great find @o KB o! I've also found it surprisingly hard to get rid of asset bundles in my project when switching away from asset bundles and including images directly in my project.

Here's my full workaround:

  1. Copy each image out of your .xcassets image bundle to a new directory (let's call it Images/). See below for a script to make this easier.
  2. Delete your .xcassets bundle. (surprisingly, removing it from the project isn't enough. In my testing, if the .xcassets bundle was anywhere in the same directory as the Xcode project or related sources, it would get copied in. Alternately, you can remove the .xcassets extension)
  3. Add all your image files in Images/ to your Xcode project
  4. Clean (cmd + shift + k)
  5. Delete the app from the target device or simulator
  6. Install and run

To make step #1 less tedious, I wrote a script to copy images out of the .xcassets bundle and into a directory of your choice: https://github.com/johnboiles/xcasset_exporter

mkdir Images
./xcasset_exporter.py MyProject/Images.xcassets Images


回答5:

I've just read about Xcode 6 beta 2: the problem will be fixed.

Downloading it as I'm writing :)