KingFisher 的 AnimatedImageView,做 gif 动画,先暂停
代码部分:
lazy var animatedPart: AnimatedImageView = {
let img = AnimatedImageView()
if let src = Bundle.main.url(forResource: "xx", withExtension: "gif"){
img.kf.setImage(with: src)
}
return img
}()
var bePaused = true{
didSet{
if bePaused{
animatedPart.stopAnimating()
}
else{
animatedPart.startAnimating()
}
}
}
关闭默认动画
处理 AnimatedImageView.swift 文件:
删掉一行 didMove()
// Reset the animator.
private func reset() {
animator = nil
if let imageSource = image?.kf.imageSource {
let targetSize = bounds.scaled(UIScreen.main.scale).size
let animator = Animator(
imageSource: imageSource,
contentMode: contentMode,

本文介绍了如何利用KingFisher的AnimatedImageView组件在iOS开发中实现gif动画的暂停功能。通过关闭默认动画,修改特定代码行,然后重新启动动画来达到暂停效果。
最低0.47元/天 解锁文章
423





