Anime
🎞 来自远东的UIView动画。
示例
let a = Animation(of: { view.frame.origin.x += 10 }, duration: 1)
let b = a.with(animations: { view.frame.origin.x -= 10 })
let timeline = AnimationTimeline(a, b, b, a).start() { (finished) in
guard finished else {
// ...
return
}
print("done")
}
// ...
timeline.needsToCancel = true
比较上面的10行代码与下面的30行代码
var isCancelled = false
let handleCancelled = {
// ...
}
let a = { view.frame.origin.x += 10 }
let b = { view.frame.origin.x -= 10 }
let start = {
UIView.animate(withDuration: 1, animations: a) { _ in
if isCancelled {
handleCancelled()
return
}
UIView.animate(withDuration: 1, animations: b) { _ in
if isCancelled {
handleCancelled()
return
}
UIView.animate(withDuration: 1, animations: b) { _ in
if isCancelled {
handleCancelled()
return
}
UIView.animate(withDuration: 1, animations: a) { _ in
print("done")
}
}
}
}
}
start()
// ...
isCancelled = true
动画也可以配置得更灵活,并且在飞行中追加
var z = b
z.animations = { /* ... */ }
z.type = .keyframed(options: [])
// ...
timeline.append(z)
要运行示例项目,首先克隆仓库,然后在示例目录中执行pod install
。
要求
Swift 4+
安装
Anime可以通过CocoaPods安装。要安装它,只需将以下行添加到您的Podfile中
pod "Anime"
作者
Peng Wang,[email protected]
许可协议
动画可在MIT许可协议下使用。关于更多信息,请查看LICENSE文件。