YYAnimatedImageView 加载GIF 不能重复播放,播放一次就结束了

关于使用YYAnimatedImageView 加载动画,可参考 博客 YYImage: 修复了iOS14的bug 本文主要介绍,无法重复播放的问题。

先上效果:

原因分析:

YYAnimatedImage 协议提供一个方法(animatedImageLoopCount)获取循环模式 0 循环播放,默认1 播放一次,YYImage,YYFrameImage等都遵循该协议,但该方法只读,因此只要设置该属性为0,即可循环播放

方案一:
监听 YYAnimatedImageView 的 currentAnimatedImageIndex 当 播放到总末尾(获取当前gif 总帧数可调用YYImage 的 animatedImageFrameCount 方法或者YYAnimatedImageView 的 私有属性 _totalFrameCount,使用 KVO 获取),调用 stopAnimating 方法重新播放

方法二:(推荐)

使用KVO直接设置私有属性为循环播放,即:

 let _img = YYImage.init(named: "IMG_1375.GIF")
 //let _count = _img?.animatedImageFrameCount()
 //_img?.animatedImageLoopCount()
 let _imgView = YYAnimatedImageView.init(image: _img)
 _imgView.backgroundColor = .clear
 _imgView.setValue(0, forKey: "_totalLoop")

 有相关问题欢迎留言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追夢秋陽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值