在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):lkzhao/YetAnotherAnimationLibrary开源软件地址(OpenSource Url):https://github.com/lkzhao/YetAnotherAnimationLibrary开源编程语言(OpenSource Language):Swift 98.8%开源软件介绍(OpenSource Introduction):Yet Another Animation LibraryDesigned for gesture-driven animations. Fast, simple, & extensible! It is written in pure swift 3.1 with protocol oriented design and extensive use of generics. Consider this as a swift optimized version of facebook's pop. It plays nicer with swift and faster too. Fast:
Simple:
Extensible:
Installationpod "YetAnotherAnimationLibrary" UsageAnimation// Spring animation
view.yaal.center.animateTo(CGPoint(x:50, y:100))
view.yaal.alpha.animateTo(0.5, stiffness: 300, damping: 20)
// Curve(Basic) animation
view.yaal.frame.animateTo(CGRect(x:0, y:0, width:50, height:50), duration:0.5, curve: .linear)
// Decay Animation
view.yaal.center.decay(initialVelocity:CGPoint(x:100, y:0)) Observe Changes// observe value changes
view.yaal.center.value.changes.addListener { oldVelocity, newVelocity in
print(oldVelocity, newVelocity)
}
// observe velocity changes
view.yaal.center.velocity.changes.addListener { oldVelocity, newVelocity in
print(oldVelocity, newVelocity)
} Chaining Reactions// when scale changes, also change its alpha
// for example if view's scale animates from 1 to 0.5. its alpha will animate to 0.5 as well
view.yaal.scale.value => view.yaal.alpha
// equvalent to the following
// view.yaal.scale.value.changes.addListener { _, newScale in
// view.yaal.alpha.animateTo(newScale)
// }
// optionally you can provide a mapping function in between.
// For example, the following code makes the view more transparent the faster it is moving
view.yaal.center.velocity => { 1 - $0.magnitude / 1000 } => view.yaal.alpha
// equvalent to the following
// view.yaal.center.velocity.changes.addListener { _, newVelocity in
// view.yaal.alpha.animateTo(1 - newVelocity.magnitude / 1000)
// } Set Value (Notify listeners)// this sets the value directly (not animate to). Change listeners are called.
// Velocity listeners will receive a series of smoothed velocity values.
view.yaal.center.setTo(gestureRecognizer.location(in:nil)) Advance UsagesReact to changesAnimate is very efficient at observing animated value and react accordingly. Some awesome effects can be achieved through observed values. For example, here is a simple 2d rotation animation thats made possible through observing the center value's velocity. override func viewDidLoad() {
// ...
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tap(gr:))))
squareView.yaal.center.velocity => { $0.x / 1000 } => squareView.yaal.rotation
}
func tap(gr: UITapGestureRecognizer) {
squareView.yaal.center.animateTo(gr.location(in: view))
} Animate also provide smooth velocity interpolation when calling For example. the following does a 3d rotate animation when dragged override func viewDidLoad() {
// ...
squareView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(pan(gr:))))
squareView.yaal.perspective.setTo(-1.0 / 500.0)
squareView.yaal.center.velocity => { $0.x / 1000 } => squareView.yaal.rotationY
squareView.yaal.center.velocity => { -$0.y / 1000 } => squareView.yaal.rotationX
}
func pan(gr: UIPanGestureRecognizer) {
squareView.yaal.center.setTo(gr.location(in: view))
} Custom propertyTo animate custom property, just create an animation object by calling
class Foo {
var volumn: Float = 0.0
lazy var volumnAnimation: SpringAnimation<Float>
= SpringAnimation(getter: { [weak self] in self?.volumn },
setter: { [weak self] in self?.volumn = $0 })
}
volumnAnimation.animateTo(0.5) If your class inherits from NSObject, then it is even easier by using the built in animation store.
via extension & |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论