- Notifications
You must be signed in to change notification settings - Fork77
Your fast and friendly physics-based animation system.
License
yapstudios/YapAnimator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
YapAnimator is your fast and friendly physics-based animation system. YapAnimator was built with ease-of-use in mind, keepingyou sane and your designer very,very happy. All animations are interruptable, include completion blocks, and allow you to apply forces to them (e.g. adding the velocity from a gesture in a transition). We've includedAnimatable
protocol conformance for some commonly animated types (CG
types), but it's really easy to add conformance to any other type.You can animate anything that you can represent and compose with an array ofDouble
s — view properties, music volume, morphing between bezier paths, colors, smoothing brush strokes, the list goes on… use your imagination!
Because it's insanely easy to use and makes beautiful animations, that's why. There are other physics-based animation systems out there (e.g. UIKit's spring animations, Facebook's Pop), but they still require writing too much code, bookkeeping, and hand-holding for our taste. YapAnimator represents a distilled n-th iteration of code that we've been using in our own apps for years. We find it invaluable in our day-to-day and think that you will too.
YapAnimator comes with a handy extension bolted on toCALayer
andUIView
/NSView
, providing one-liner animations under theanimatedLayer
andanimated
properties, respectively.
func handle(gesture:UIPanGestureRecognizer){if gesture.state==.began{squircle.animated.cornerRadius.animate(to: squircle.bounds.width/2.0)squircle.animated.rotationZ.animate(to:.pi)elseif gesture.state==.changed{squircle.animated.position.instant(to: gesture.location(in:nil))}elseif gesture.state==.ended{squircle.animated.position.animate(to:self.view.center)squircle.animated.cornerRadius.animate(to:0)squircle.animated.rotationZ.animate(to:0)}}
Creating a custom animator is straightforward:
initialValue
This sets the initial value of the animator and informs it what type it will be animating.willBegin
Called just before motion starts. Return the actual value of the property that you'll be animating. This allows the animator to sync up with that value in case it was changed outside of the scope of the animator.(optional)eachFrame
Called each frame of the animation — this is typically where you'd apply the animator'scurrent.value
to the property that you're animating. You can also use it to check values to trigger other actions / animations.
frameAnimator=YapAnimator(initialValue: square.frame, willBegin:{[unowned self]inreturnself.square.frame}, eachFrame:{[unowned self](animator)inself.square.frame= animator.current.value})
frameAnimator.bounciness=1.5frameAnimator.animate(to: square.frame.insetBy(dx:-50, dy:-50), completion:{ animator, wasInterruptedinif !wasInterrupted{// animate back to the original valueanimator.animate(to: animator.current.value.insetBy(dx:50, dy:50))}})
Feel free toask your question in an issue. We will respond there, and amend this read me/start a wiki if the answer seems like it would benefit others.
YapAnimator is owned and maintained byYap Studios.
About
Your fast and friendly physics-based animation system.