定义:PAG(Portable Animated Graphics)是腾讯自主研发的一套完整的动画工作流解决方案,助力于将 AE 动画方便快捷的应用于各平台终端。
使用过程:
1、引用三方库:import libpag
2、初始化pagview,加载本地pag资源文件,设置循环播放次数,缩放模式,监听动效执行过程等
public lazy var animateView: PAGView = {
let animate = PAGView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
animate.setPath(Bundle.main.path(forResource: "test", ofType: "pag"))
animate.isUserInteractionEnabled = false
//animate.setRepeatCount(MAXINTERP)//重复播放pag动效
animate.setRepeatCount(1)//只播放一次
animate.setScaleMode(PAGScaleModeStretch)
return animate
}()
2.1、缩放模式枚举(PAGScaleMode)
typedef enum {
// The content is not scaled.
PAGScaleModeNone = 0,
// The content is stretched to fit.
PAGScaleModeStretch = 1,
// The content is scaled with respect to the original unscaled image's aspect ratio. This is the
// default value.
PAGScaleModeLetterBox = 2,
// The content is scaled to fit with respect to the original unscaled image's aspect ratio. This
// results in cropping
// on one axis.
PAGScaleModeZoom = 3,
} PAGScaleMode;
2.2、遵守PAGViewListener协议,监听动效执行过程
func onAnimationStart(_ pagView: PAGView!) {
print("动效开始执行")
}
func onAnimationCancel(_ pagView: PAGView!) {
print("动效取消")
}
func onAnimationRepeat(_ pagView: PAGView!) {
print("重复执行")
}
func onAnimationEnd(_ pagView: PAGView!) {
print("动效结束")
}
3、添加pagview,开始执行
self.view.addSubview(animateView)
animateView.play()
网友评论