基于图层的动画库 – Anima

Anima

Anima是基于图层的动画库,应用于Swift3.

它会使顺序和分组动画更容易

编写如下

let startAnimations: [AnimaType] = [.moveByY(-50), .rotateByZDegree(90)]
let moveAnimations: [AnimaType] = [.moveByX(50), .rotateByZDegree(90)]
let endAnimations: [AnimaType] = [.moveByY(-50), .rotateByZDegree(90)]

animaView.layer.anima
    .then(.opacity(1.0))
    .then(group: startAnimations)
    .then(group: moveAnimations, options: labelAnimaOption(index: 0))
    .then(group: moveAnimations, options: labelAnimaOption(index: 1))
    .then(group: moveAnimations, options: labelAnimaOption(index: 2))
    .then(group: moveAnimations, options: labelAnimaOption(index: 3))
    .then(group: endAnimations, options: labelAnimaOption(index: 4))
    .then(group: [.scaleBy(0.0), AnimaType.opacity(0.0)])

func labelAnimaOption(index: Int) -> [AnimaOption] {
    let labelAnima = labels[index]?.layer.anima

    return [.completion({
        labelAnima?.then(.opacity(1)).fire()
    })]
}

需求

wift3 iOS9.0

特性

  • 从easings.set 所有时序模式的实现
  • 弹簧动画
  • 类型安全的动画KeyPath()使用方法

使用方法

移动位置

layer.anima.then(.moveByX(50)).fire()

组合动画

layer.anima
    .then(group: [.moveByX(200),
                .scaleBy(1.5),
                .rotateByZDegree(180)])
    .fire()

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:基于图层的动画库 – Anima