将 GIF 文件添加到 Xcode 资产文件夹

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

Adding GIF files to Xcode assets folder

iosxcodegif

提问by FS.O5

I have an app that uses some GIF files using SwiftyGif(a 3rd party API that adds GIF support to the class).

我有一个使用一些 GIF 文件的应用程序SwiftyGif(向类添加 GIF 支持的第 3 方 API)

The problem is that the GIF size should be 30x30. I've added a 30x30 file to the project but I need the @2xand @3xfiles. As you may know, Xcode has a Images.xcassetsfolder that's contains @1x, @2x, @3xfiles and it has an algorithm the chooses the appropriate file.

问题是 GIF 大小应该是 30x30。我已将 30x30 文件添加到项目中,但我需要@2x@3x文件。您可能知道,Xcode 有一个Images.xcassets包含@1x, @2x,@3x文件的文件夹,它有一个算法来选择合适的文件。

I've tried to add the GIF file to this folder but it's not possible, so how can I use the @1x, @2xand @3xmethod with a GIF file?

我已尝试将 GIF 文件添加到此文件夹,但这是不可能的,那么我如何对 GIF 文件使用@1x, @2xand@3x方法?

回答by Mohammad Sadiq

You have to manually add the folder with .imageset extension. Right click on Assets.xcassets folder and go to location in finder. Add the asset folder with .imageset extensionn. Drop the 1x, 2x and 3x files to that folder. Add one file Contents.json, and add the file names in that file.

您必须手动添加扩展名为 .imageset 的文件夹。右键单击 Assets.xcassets 文件夹并转到查找器中的位置。添加扩展名为 .imageset 的资产文件夹。将 1x、2x 和 3x 文件放到该文件夹​​中。添加一个文件 Contents.json,并在该文件中添加文件名。

{
  "images" : [
    {
      "idiom" : "universal",
      "scale" : "1x",
      "filename" : "[email protected]"
    },
    {
      "idiom" : "universal",
      "scale" : "2x",
      "filename" : "[email protected]"
    },
    {
      "idiom" : "universal",
      "scale" : "3x",
      "filename" : "[email protected]"
    }
  ],
  "info" : {
    "author" : "xcode",
    "version" : "1"
  }
}