iOS开发-SVGA Animation实现直播间礼物特效

公司做的直播项目正处在优化阶段,前期仓促上线,所以直播间的礼物特效使用的是帧动画,勉强说得说去!

推荐阅读 iOS重拾直播系列-直播间礼物效果

SVGA Animation

全新的动画格式,高性能动画播放体验, SVGA 是一种同时兼容 iOS / Android / Web 多个平台的动画格式。

SVGA介绍

SVGA集成指南

SVGA集成指南

iOS

  • 使用 CocoaPods 集成源码,将以下依赖

  • pod 'SVGAPlayer'

  • 添加至 Podfile 文件。

  • 使用代码或 IB 添加 SVGAPlayer 至 View 中,具体方法参见:https://github.com/yyued/SVGAPlayer-iOS

Android

  • 使用 Gradle 集成源码,添加 JitPack.io 到 root build.gradle 中
allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
  • 添加以下依赖:
    compile 'com.github.yyued:SVGAPlayer-Android:2.0.0'

  • 根据需要修改版本号,要获取最新的版本请点入:
    https://jitpack.io/#yyued/SVGAPlayer-Android/。

  • 使用代码或 XML 添加 SVGAImageView 至 View 中,具体方法参见:https://github.com/yyued/SVGAPlayer-Android。

Web

  • 直接在: https://github.com/yyued/SVGAPlayer-Web 下载 build/svga.min.js,
    并添加至目标页面。

  • 或使用 npm install svgaplayerweb —save添加依赖,
    并在需要使用的 js 中添加 require('svgaplayerweb') 添加 Div 容器,并加载动画,
    具体方法参见: https://github.com/yyued/SVGAPlayer-Web。

如何使用

简单集成的demo https://github.com/TsuiOS/SVGSDemo.git
参考文档或者官方Demo很容易集成! 后续直播项目中集成的时候再更新中间遇到的问题

三种方式加载动画

- (void)parseWithURL:(nonnull NSURL *)URL
     completionBlock:(void ( ^ _Nonnull )(SVGAVideoEntity * _Nullable videoItem))completionBlock
        failureBlock:(void ( ^ _Nullable)(NSError * _Nullable error))failureBlock;

- (void)parseWithData:(nonnull NSData *)data
             cacheKey:(nonnull NSString *)cacheKey
      completionBlock:(void ( ^ _Nullable)(SVGAVideoEntity * _Nonnull videoItem))completionBlock
         failureBlock:(void ( ^ _Nullable)(NSError * _Nonnull error))failureBlock;

- (void)parseWithNamed:(nonnull NSString *)named
              inBundle:(nullable NSBundle *)inBundle
       completionBlock:(void ( ^ _Nullable)(SVGAVideoEntity * _Nonnull videoItem))completionBlock
          failureBlock:(void ( ^ _Nullable)(NSError * _Nonnull error))failureBlock;


参考资料

开源代码
SVGA简介 SVGA-Format
SVGA示例动画 SVGA-Samples

你可能感兴趣的:(iOS开发-SVGA Animation实现直播间礼物特效)