Designed 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:

  • Uses SIMD types and instructions for calculation
  • Better compiler optimization through swift generics

Simple:

  • Supports Curve(Basic), Spring, & Decay animations out of the box
  • Easy API for animating common animatable properties. (checkout the Extensions folder for list of included properties)
  • Type safety guaranteed when assigning animation values
  • Observable, including value, velocity, and target value
  • Builtin chaining operator to easily react to changes in value
  • Provide velocity interpolation with gestures

Extensible:

  • Supports custom property
  • Supports custom animatable type
  • Supports custom animation

Installation

pod "YetAnotherAnimationLibrary"Copy the code

Animation

// 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))Copy the code

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)
// }Copy the code

Advance Usages

Custom property

To animate custom property, just create an animation object by calling SpringAnimation(getter:setter:). Use the animation object to animate and set the values. There are 4 types of animations provided by Animate:

  • SpringAnimation
  • CurveAnimation
  • DecayAnimation
  • MixAnimation (does all three types of animation)
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)Copy the code

If your class inherits from NSObject, then it is even easier by using the built in animation store.

via yaal_register & yaal_animationFor

// or register ahead of time
yaal_register(key: "volumn".getter: {[weak self] in self?.volumn },
              setter: {[weak self] in self?.volumn = $0 })

// and retrieve the animation object through the same key.
yaal_animationFor(key: "volumn")!.animateTo(0.5)

// NOTE: that this method have limited type safety. You can basically pass any animatable type into `animateTo()`
// There is nothing to stop you from doing the following. but they will crash at run time
yaal_animationFor(key: "volumn")!.animateTo(CGSize.zero)
yaal_animationFor(key: "volumn")!.animateTo(CGRect.zero)Copy the code

Custom Animation

Just subclass Animation and override update(dt:TimeInterval) method. If your animation need getter & setter support, subclass ValueAnimation instead. Checkout the builtin animations for example.