xcode 如何告诉资产目录 (.xcassets) 为多个图像井使用相同的图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19061957/
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 03:57:08  来源:igfitidea点击:

How can I tell Asset Catalog (.xcassets) to use the Same Image for Multiple Image Wells?

iosxcodexcode5xcasset

提问by JRG-Developer

We have several Xcode app projects, and we're upgrading all of them to use the latest Xcode 5 features, including Asset Catalogs (.xcassets).

我们有几个 Xcode 应用程序项目,我们正在升级所有这些项目以使用最新的 Xcode 5 功能,包括资产目录 ( .xcassets)。

All of our default(launch) images already include spacing for the status bar, and we want to use these images for both the iOS 5,6and iOS 7launch images. Further, we don'twant to include multiple copies of the same image in the project.

我们所有的default(启动)图像都已经包含状态栏的间距,我们希望将这些图像用于启动图像iOS 5,6iOS 7启动图像。此外,我们不想在项目中包含同一图像的多个副本。

One of our projects is correctly set to use the same images for both of these image well sets. However, this was setup more so by accident.

我们的一个项目已正确设置为对这两个图像井集使用相同的图像。然而,这是偶然设置的。

Besides editing the Contents.jsonfile directly (which is a last-resort workaround if need be), how can we do this using the Xcode GUI editor for Asset Catalog?

除了Contents.json直接编辑文件(如果需要,这是最后的解决方法),我们如何使用 Asset Catalog 的 Xcode GUI 编辑器执行此操作?

What we've already tried

我们已经尝试过的

1) Dragging and dropping the image to a different position... just moves the image to the other set

1)将图像拖放到不同的位置......只需将图像移动到另一组

2) Dragging and dropping the same file from Finder to the Asset Catalog... creates a new copy of the image

2) 将相同的文件从 Finder 拖放到资产目录...创建图像的新副本

3) Dragging and dropping the image with option(alt) pressed... creates a new copy of the image

3)按住option( ) 拖放图像alt... 创建图像的新副本

回答by Erwin Zwart

You can right click on the .xcassets file and choose 'Show in Finder'. Go to the 'Image.launchimage' folder and open the Contents.json file in a text editor. Here you can see that unassigned slots don't contain an "filename". You can add this manually. For example change the following:

您可以右键单击 .xcassets 文件并选择“在 Finder 中显示”。转到“Image.launchimage”文件夹并在文本编辑器中打开 Contents.json 文件。在这里您可以看到未分配的插槽不包含“文件名”。您可以手动添加它。例如更改以下内容:

{
    "orientation" : "landscape",
    "idiom" : "ipad",
    "extent" : "full-screen",
    "minimum-system-version" : "7.0",
    "scale" : "2x"
}

Into:

进入:

{
    "orientation" : "landscape",
    "idiom" : "ipad",
    "extent" : "full-screen",
    "minimum-system-version" : "7.0",
    "filename" : "Default-Landscape@2x~ipad.png",
    "scale" : "2x"
}

Now safe the file, and voila!

现在保护文件,瞧!

回答by coneybeare

I solved this by using build scripts to copy the right xcassets file in for each target. Details here

我通过使用构建脚本为每个目标复制正确的 xcassets 文件解决了这个问题。详情在这里

回答by Christopher Schardt

I think I've found the solution: Simply drag the default images that you want to be used for iOS 6 and 7 into the iOS 6 bucket. You get a warning about not having an iOS7-only image but the build works in the iOS7 simulato, an iOS7 iPhone and an iOS7 iPad.

我想我已经找到了解决方案:只需将要用于 iOS 6 和 7 的默认图像拖到 iOS 6 存储桶中即可。您会收到关于没有仅适用于 iOS7 的图像的警告,但该构建可以在 iOS7 模拟器、iOS7 iPhone 和 iOS7 iPad 中运行。

回答by Christopher Schardt

I solved this by removing old xcassets and added new xcassets by using Don't use app catalogs

我通过删除旧的 xcassets 并使用 Don't use app catalogs 添加新的 xcassets 解决了这个问题

回答by d.ennis

In my case I am using cocoa pods. The cocoa pods script Pods-resources.shsomehow caused the problem. Removing the asset parts from the script solved the problem.

就我而言,我使用的是可可豆荚。可可豆脚本Pods-resources.sh以某种方式导致了这个问题。从脚本中删除资产部分解决了这个问题。

Make sure to clean your project and delete derived data folder.

确保清理您的项目并删除派生数据文件夹。

Parts to be deleted can be found here:

要删除的部分可以在这里找到:

https://stackoverflow.com/a/21309102/832111

https://stackoverflow.com/a/21309102/832111

回答by Qiulang

I upgraded to cocopods 0.37 and the problem was solved. If you used cocopods then it was probably its fault.

我升级到 cocopods 0.37,问题解决了。如果你使用 cocopods 那么它可能是它的错。