ios - 动画 GIF 作为 Swift 中的背景

标签 ios swift gif

我正在尝试将我的应用程序背景设为动画 gif。这是我的代码,因为我收到此行的错误“exc_bad_instruction”:images.append(UIImage(named: imageNames[i])!)

我不明白问题是什么。这是代码:

var imageNames = ["tmp-0.gif", "tmp-1.gif", "tmp-2.gif", "tmp-3.gif", "tmp-4.gif", "tmp-5.gif", "tmp-6.gif", "tmp-7.gif", "tmp-8.gif", "tmp-9.gif", "tmp-10.gif", "tmp11.gif", "tmp-12.gif", "tmp-13.gif", "tmp-14.gif", "tmp-15.gif", "tmp-16.gif", "tmp-17.gif", "tmp-18.gif", "tmp-19.gif"]

    var images = [UIImage]()

    for i in 0..<imageNames.count{
        images.append(UIImage(named: imageNames[i])!)

    }

    theGif.animationImages = images
    theGif.animationDuration = 1.0
    theGif.startAnimating()

最佳答案

如果您正在考虑为背景使用动画 GIF,而不是尝试解耦 GIF 中的所有帧并使用 UIImageView 的动画功能,我建议使用合适的动画 GIF 库。

Flipboard's FLAnimatedImage library显然是比较流行的之一(我没有亲自使用过,所以我不能肯定地说)。它是 Objective-C,但它应该可以毫无问题地与 Swift 互操作。

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

相关文章:

ios - 我们应该使 tapGesture 组件成为 IBAction 还是 IBOutlet 来捕获点击事件?

ios - 在 Swift 中编写库时使用开源

java - 调整 .GIF 图像的大小

objective-c - StoryBoard 中未设置 View Outlet

ios - BundlePath 为零,但 NSLog 打印正确的路径

ios - 自定义TextField在SwiftUI代码中的VStack中不起作用

ios - 在 iOS 中的视频上添加 GIF 水印

ios - 是否可以强制 MapKit 在不聚类的情况下显示所有注释?

swift - 如何从 Swift 中的 UInt8 变量中获取 N 位?

image-processing - 为什么 ImageMagick 生成的 '.png' 文件比 '.jpg' 和 '.gif' 文件大得多?