Anime
🎞  UIView animation from the Far East.
Example
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
Compare the above 10 lines with the below 30 lines:
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
Animations can also be configured more flexibly, and appended in-flight:
var z = b
z.animations = { /* ... */ }
z.type = .keyframed(options: [])
// ...
timeline.append(z)
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
Swift 4+
Installation
Anime is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Anime"
Author
Peng Wang, [email protected]
License
Anime is available under the MIT license. See the LICENSE file for more info.