Animation

  • Manages the application of animations to a value.

    let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
    
    let sizeAnimator = Animator(boundTo: view, keyPath: \.bounds.size)
    
    /// Spring physics will move the view's size to the new value.
    sizeAnimator.spring(to: CGSize(width: 300, height: 300))
    
    /// Some time in the future...
    
    /// The value will keep the same velocity that it had from the preceeding
    /// animation, and a decay function will slowly bring movement to a stop.
    sizeAnimator.decay(drag: 2.0)
    
    See more

    Declaration

    Swift

    public final class Animator<Value> where Value : VectorConvertible
  • This class is used to drive a single animation to completion. It is one-shot, so a runner is no longer useful after the animation that it is driving completes.

    • They begin in a pending state.
    • Then enter the running state after start() is called.
    • If the animation finishes, the runner enters the completed (finished) state.
    • If cancel() is called on the runner while in a running state, the runner enters the completed (cancelled) state.
    import Advance
    
    let animation = 0.0.animation(
        to: 100.0,
        duration: 0.6,
        timingFunction: UnitBezier.easeIn)
    
    let runner = AnimationRunner(animation: animation)
        .onChange { value in
            /// Do something with the value.
        }
        .onCancel {
            /// The animation was cancelled before it could finish.
        }
        .onFinish {
            /// The animation finished successfully.
         }
    
    /// Kick off the animation
    runner.start()
    
    

    The resulting runner can be used to cancel the animation or to add additional observers or completion handlers.

    See more

    Declaration

    Swift

    public final class AnimationRunner<Value> where Value : VectorConvertible
  • A protocol which defines the basic requirements to function as a time-advancable animation.

    Conforming types can be used to animate values.

    See more

    Declaration

    Swift

    public protocol Animation : Advanceable