gpt4 book ai didi

ios - 在 Swift 中制作 Gif 动画

转载 作者:行者123 更新时间:2023-11-29 01:40:57 25 4
gpt4 key购买 nike

我一直在尝试在 Swift 中制作 GIF 动画,但它就是行不通。我想我找到了一个方法,但是有一个错误,请帮助。

代码如下:

@IBOutlet var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
// (Here is the error it states "Cannot assign a value of type '[UIImage?]' to a value of type '[UIImage]?'")
imageView.animationImages = [

UIImage(named: "logo1.jpg"),
UIImage(named: "logo2.jpeg"),
UIImage(named: "logo3.png")
]

imageView.animationDuration = 3
imageView.startAnimating()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
// ...
}

最佳答案

您可以直接运行gif文件,点击下面的链接;

https://github.com/kaishin/gifu

How to load GIF image in Swift?

就您代码中的问题而言,正如“Leo Dabus”已经指出的那样,您是否没有取消包装 UIImage 实例。通过以下修改尝试相同的代码。

imageView.animationImages = [

UIImage(named: "logo1.jpg")!, //File Extension would not be required if .png
UIImage(named: "logo2.jpeg")!, //File Extension would not be required if .png
UIImage(named: "logo3.png")!
]

imageView.animationDuration = 3
imageView.startAnimating()

关于ios - 在 Swift 中制作 Gif 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32390205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com