Animator

public final class Animator<A: AnimationType>

Runs an animation until the animations finishes, or until cancel() is called.

The Animator class is one-shot: It runs the animation precisely one time.

It starts in the Pending state. From here either:

  • It enters the running state. This occurs if start() is called.
  • It is cancelled. This occurs if cancel() is called, and causes the animator to enter the Completed state, with a result of Cancelled.

After entering the Running state, the started event is fired. The animation then updates on every frame, triggering the changed event each time, until either:

  • The animation finishes on its own, after which the animator enters the Completed state, with a result of Finished.
  • cancel() is called, after which the animator enters the Completed state, with a result of Cancelled.

When the animator enters the Completed state, it triggers either the cancelled or finished event, depending on the result. After entering the Completed state, the animator is finished and no further state changes can occur.

  • The current state of the animator. Animators begin in a running state, and they are guarenteed to transition into either the cancelled or finished state exactly one time – no further state changes are allowed.

    Declaration

    Swift

    fileprivate (set) public var state: AnimatorState = .pending
  • The animation that is being run.

    Declaration

    Swift

    fileprivate (set) public var animation: A
  • Fired when the animator starts running

    Declaration

    Swift

    public let started = Event<A>()
  • Fired after every animation update.

    Declaration

    Swift

    public let changed = Event<A>()
  • Fired if the animator is cancelled.

    Declaration

    Swift

    public let cancelled = Event<A>()
  • Fired when the animation finishes.

    Declaration

    Swift

    public let finished = Event<A>()
  • Creates a new animator.

    Declaration

    Swift

    public init(animation: A, loop: Loop = Loop.shared)

    Parameters

    animation

    The animation to be run.

  • Starts a pending animation

    If the animator is not in a pending state, calling start() will have no effect.

    Declaration

    Swift

    public func start()
  • Cancels the animation.

    If the animator is in a running or pending state, this will immediately transition to the cancelled state (and call any onCancel observers). If the animator is already cancelled or finished, calling cancel() will have no effect.

    Declaration

    Swift

    public func cancel()