按照视频中的说明:https://www.youtube.com/watch?v=Rm61mxcSD4U&t=95s
添加了我的动画GIF文件one.GIF
。
尝试运行,但得到错误:
SwiftGif:这个名为“one”的图像不存在。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var gifView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
gifView.loadGif(name: "one")
}
}
在您的文件one.GIF
中,扩展名全部为大写。但是,你可以在the source code看到它正在寻找小写的.gif
。
你需要将one.GIF
重命名为one.gif
。
来自Getting References to Bundle Resources: The Bundle Search Pattern:
重要提示:在bundle目录中搜索资源文件时,bundle接口会考虑大小写。这种区分大小写的搜索甚至发生在文件系统(例如HFS +)上,这些文件系统在文件名方面不区分大小写。