SVGAPlayer-Lite 是一个轻量级高性能的 SVGA 动画播放器,基于 SVGAPlayer 优化而来。
- 🚀 轻量级实现,优化了性能和内存占用
- 📦 支持 CocoaPods 集成
- 🎨 完整支持 SVGA 动画格式
- 💪 高性能渲染引擎
- 🔧 易于集成和使用
在你的 Podfile 中添加:
pod 'SVGAPlayerLite'然后运行:
pod install- 克隆或下载本仓库
- 将
Source文件夹拖入你的项目 - 添加依赖:
- SSZipArchive (>= 1.8.1)
- Protobuf (~> 3.4)
#import <SVGAPlayerLite/SVGA.h>
// 创建播放器
SVGAPlayer *player = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self.view addSubview:player];
// 创建解析器
SVGAParser *parser = [[SVGAParser alloc] init];
// 从网络加载
[parser parseWithURL:[NSURL URLWithString:@"https://example.com/animation.svga"]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
if (videoItem) {
player.videoItem = videoItem;
[player startAnimation];
}
} failureBlock:^(NSError * _Nullable error) {
NSLog(@"加载失败: %@", error);
}];
// 或从本地加载
[parser parseWithNamed:@"animation" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
if (videoItem) {
player.videoItem = videoItem;
[player startAnimation];
}
} failureBlock:nil];import SVGAPlayerLite
// 创建播放器
let player = SVGAPlayer(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
view.addSubview(player)
// 创建解析器
let parser = SVGAParser()
// 从网络加载
parser.parse(with: URL(string: "https://example.com/animation.svga"), completionBlock: { videoItem in
player.videoItem = videoItem
player.startAnimation()
}, failureBlock: { error in
print("加载失败: \(error)")
})
// 或从本地加载
parser.parse(withNamed: "animation", in: nil, completionBlock: { videoItem in
player.videoItem = videoItem
player.startAnimation()
}, failureBlock: nil)player.loops = 0; // 0 表示无限循环
player.loops = 3; // 播放 3 次[player startAnimation]; // 开始播放
[player pauseAnimation]; // 暂停播放
[player stopAnimation]; // 停止播放
[player stepToFrame:10 andPlay:YES]; // 跳转到指定帧// 替换图片
UIImage *image = [UIImage imageNamed:@"replacement"];
[player setImage:image forKey:@"key" referenceLayer:nil];
// 替换文本
NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"Hello"];
[player setAttributedText:text forKey:@"key"];player.delegate = self;
// 实现代理方法
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
NSLog(@"动画播放完成");
}- iOS 9.0+
- Xcode 11.0+
- SSZipArchive (>= 1.8.1)
- Protobuf (~> 3.4)
SVGAPlayer-Lite 是基于 SVGAPlayer 的轻量级版本,主要改进包括:
- 优化了内存管理
- 改进了渲染性能
- 简化了部分 API
- 更好的稳定性
Apache License 2.0
欢迎提交 Issue 和 Pull Request!
- 初始版本
- 支持 CocoaPods 集成
- 基于 SVGAPlayer 优化