APNG(动画播放)

大约 2 分钟

APNG(动画播放)

播放APNG图片动画的组件

组件使用示例open in new window

属性

支持所有基础属性,此外还支持:

src

设置APNG的源文件路径,支持URL或本地文件路径

参数描述类型
src源文件路径String
@Page("demo_page")
internal class TestPage : BasePager() {
    override fun body(): ViewBuilder {
        return {
            attr {
                allCenter()
            }
            APNG {
                attr {
                    size(200f, 200f)
                    src("https://vfiles.gtimg.cn/wuji_dashboard/xy/componenthub/5vcy152h.png?test=4")
                }
                event {
                    animationStart {
                        KLog.i("APNG", "start play animation")
                    }
                }
            }
        }
    }
}







 
 
 
 
 
 
 
 
 
 
 



repeatCount

设置动画重复次数,默认值为 0,表示动画将无限次播放

参数描述类型
repeatCount动画重复次数Int

autoPlay

设置是否自动播放,默认值为 true

参数描述类型
play是否自动播放Boolean

事件

支持所有基础事件,此外还支持:

loadFailure

设置加载失败时的事件回调

animationStart

设置动画开始时的事件回调

animationEnd

设置动画结束时的事件回调

适配器

iOS

在开源版本中,移除了APNG组件对第三方库QQAPNGView的集成适配,需要业务自行实现APNG适配器。

重新实现APNG适配器

对于之前直接pod安装QQAPNGView第三方库使用APNG组件的业务,需要实现并注册APNGImageViewProtocol,比如:

// KRAPNGViewHandler.h
#import <SDWebImage/SDWebImage.h>
#import "KRAPNGView.h"

@interface KRAPNGViewHandler : SDAnimatedImageView<APNGImageViewProtocol>

@end
// KRAPNGViewHandler.m
#import "KRAPNGViewHandler.h"

@implementation KRAPNGViewHandler

+ (void)load {
    [KRAPNGView registerAPNGViewCreator:^id<APNGImageViewProtocol> _Nonnull(CGRect frame) {
        KRAPNGViewHandler *apngView = [[KRAPNGViewHandler alloc] initWithFrame:frame];
        return apngView;
    }];
}
...

详细使用示例可参考KRAPNGViewHandleropen in new window

修改已有APNG适配器

对于之前实现过APNG适配器的业务,需要对适配器进行一些修改:

  • 适配器协议名:QQAPNGImageViewProtocol --> APNGImageViewProtocol
  • 动画播放回调协议名:QQAPNGViewPlayDelegate --> APNGViewPlayDelegate
  • 开始播放动画方法:startAnimating --> startAPNGAnimating
  • 结束播放动画方法:stopAnimating --> stopAPNGAnimating