为什么我不能在 Xcode 5 中向 Images.xcassets 添加文件?

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

Why can't I add files to Images.xcassets in Xcode 5?

iosxcodeimagexcasset

提问by user3230300

When trying to add image files to Images.xcassets, there are certain images that I cannot add. I've tried both dragging-and-dropping as well as using "+" followed by "Import". In the drag-and-drop case, nothing happens. In the Import case, the files I'd like to import are grayed out and cannot be selected.

尝试将图像文件添加到 Images.xcassets 时,我无法添加某些图像。我试过拖放以及使用“+”后跟“导入”。在拖放情况下,没有任何反应。在导入的情况下,我想导入的文件是灰色的,无法选择。

I'm using Xcode 5.0.2 and I'm trying to import a JPG that's 60x105 pixels, with no transparency or layers.

我正在使用 Xcode 5.0.2,我正在尝试导入一个 60x105 像素的 JPG,没有透明度或图层。

However, some image files I can import. It's just that the ones I want I cannot for some reason. Are there limitations to the types of images you can import? I've done some googling, searching on forums, and in online developer help for more information about that but haven't found any explanation of any specific limitations on what you can import. Suppose then that no limitations exist, then is there another possible reason why can't I import some of these files?

但是,我可以导入一些图像文件。只是我想要的那些我因为某种原因不能。您可以导入的图像类型是否有限制?我已经做了一些谷歌搜索,在论坛上搜索,并在在线开发人员帮助中获取更多信息,但没有找到任何关于您可以导入的内容的任何特定限制的解释。假设不存在任何限制,那么我无法导入其中一些文件是否还有另一个可能的原因?

As an added mystery, the images I'm trying to add are images I've downloaded to do the homework for Stanford's CS 193p course on iPhone programming available on iTunes. I watched the professor of the course drag-and-drop these very files into his Images.xcassets with no problem. So why can't I do that? It seems like I must be missing something obvious!

作为一个额外的谜,我尝试添加的图像是我下载的图像,用于为 iTunes 上提供的关于 iPhone 编程的斯坦福 CS 193p 课程做作业。我看着课程教授将这些文件拖放到他的 Images.xcassets 中,没有任何问题。那为什么我不能这样做呢?似乎我必须遗漏一些明显的东西!

I'm very stuck on this and I would appreciate any suggestions!

我非常坚持这一点,我将不胜感激任何建议!

Thanks, Mark Xcode 5, OS X Mavericks (10.9.1)

谢谢,马克 Xcode 5,OS X Mavericks (10.9.1)

回答by andrewcbancroft

I've only ever had luck using PNG images inside the asset catalog. You can use the Preview to open your JPEG image and Export it to PNG.

我只有在资产目录中使用 PNG 图像才有运气。您可以使用预览打开您的 JPEG 图像并将其导出为 PNG。

回答by user3587293

I had a similar issue when trying to add a PNG file as well. I tried Importing as well as drag & dropping, and it simply wouldn't work (wouldn't give me an error, either). For some reason, I had to ensure that the filename ended in lowercase ".png" as opposed to ".PNG".

我在尝试添加 PNG 文件时也遇到了类似的问题。我尝试了导入和拖放,但它根本不起作用(也不会给我一个错误)。出于某种原因,我必须确保文件名以小写“.png”而不是“.PNG”结尾。

Not sure why it happened, but simply renaming the extension to lowercase ".png" seemed to fix the problem.

不知道为什么会这样,但简单地将扩展名重命名为小写“.png”似乎可以解决问题。