Tween

public protocol Tween : AnyObject

A handle that provides state control and customization of a tween animation.

Animation & State Properties

  • An animation closure that is invoked every time a tween is updated. These closures interpolate new values of properties and apply them back to a target instance.

    Declaration

    Swift

    typealias Animation = (TimeInterval) -> Void
  • The Ease used to interpolate values.

    Declaration

    Swift

    var ease: Ease { get set }
  • The tween’s current state, i.e., active, paused, etc.

    Declaration

    Swift

    var state: TweenState { get }

Time Properties

  • The amount of seconds before the tween starts updating after being started.

    Assigning this will not take effect until the tween is started. If the tween has already been started, it must be restarted before taking effect.

    Declaration

    Swift

    var delay: TimeInterval { get set }
  • The amount of seconds the tween takes to complete.

    Declaration

    Swift

    var duration: TimeInterval { get set }
  • The amount of seconds the tween has been active.

    The elapsed time is reset when the tween is started. If the tween is completed, the elapsed time is the same as the duration.

    Declaration

    Swift

    var elapsed: TimeInterval { get }

Callback Properties

  • Callbacks are invoked upon completion of many different events, such as when a tween has finished animating.

    Declaration

    Swift

    typealias Callback = (Tween) -> Void
  • The callback invoked every time the tween is updated.

    Declaration

    Swift

    var onUpdate: Callback? { get set }
  • The callback invoked when the tween is started.

    Declaration

    Swift

    var onStart: Callback? { get set }
  • The callback invoked when the tween is stopped.

    Declaration

    Swift

    var onStop: Callback? { get set }
  • The callback invoked when the tween is restarted.

    Declaration

    Swift

    var onRestart: Callback? { get set }
  • The callback invoked when the tween is paused.

    Declaration

    Swift

    var onPause: Callback? { get set }
  • The callback invoked when the tween is resumed.

    Declaration

    Swift

    var onResume: Callback? { get set }
  • The callback invoked when the tween is completed.

    Declaration

    Swift

    var onComplete: Callback? { get set }
  • The callback invoked when the tween is killed.

    Declaration

    Swift

    var onKill: Callback? { get set }
  • The callback invoked when the tween is revived.

    Declaration

    Swift

    var onRevive: Callback? { get set }

State Control

  • Increases the tween’s elapsed time and invokes all animation closures. These closures interpolate new values of properties and apply them back to the target instance(s). The tween will be completed if its elapsed time has reached or exceeded its duration.

    If the tween is in a delayed state, the elapsed delay is updated instead; otherwise, the tween can only be updated if in an active state.

    Declaration

    Swift

    @discardableResult
    func update(by deltaTime: TimeInterval) -> Bool

    Parameters

    deltaTime

    The amount of seconds passed since the last update.

    Return Value

    true if the tween is successfully updated.

  • Starts the tween for updates, putting it in an active state from its beginning values. The tween can only be started if it’s in a new or inactive state.

    Declaration

    Swift

    @discardableResult
    func start() -> Bool

    Return Value

    true if the tween is successfully started.

  • Stops the tween from updating, putting it in an inactive state. The tween can only be stopped if it’s in an active, delayed, or paused state.

    Declaration

    Swift

    @discardableResult
    func stop() -> Bool

    Return Value

    true if the tween is successfully stopped.

  • Stops the tween, then immediately starts it over again from the beginning. The tween can only be restarted if it’s not in a killed state.

    Declaration

    Swift

    @discardableResult
    func restart() -> Bool

    Return Value

    true if the tween is successfully restarted.

  • Pauses the tween, maintaining its current progress. The tween can only be paused if it’s in an active or delayed state.

    Declaration

    Swift

    @discardableResult
    func pause() -> Bool

    Return Value

    true if the tween is successfully paused.

  • Resumes the tween, continuing where it left off before being paused. The tween can only be resumed if it’s in a paused state.

    Declaration

    Swift

    @discardableResult
    func resume() -> Bool

    Return Value

    true if the tween is successfully resumed.

  • Completes updates on the tween, jumping to its ending values if not already there. The tween can only be completed if it’s not already in a complete state and not in a killed state. The tween will automatically be killed if Defaults.autoKillCompletedTweens is true.

    Declaration

    Swift

    @discardableResult
    func complete() -> Bool

    Return Value

    true if the tween is successfully completed.

  • Kills the tween in place, halting at its current values, and removes it from Tweener‘s list of tracked tweens. The tween can only be killed if it’s not already in a killed state.

    Declaration

    Swift

    @discardableResult
    func kill() -> Bool

    Return Value

    true if the tween is successfully killed.

  • Revives the tween, putting it in a new state, and re-adds it to Tweener‘s list of tracked tweens. The tween can only be revived if it’s in a killed state.

    Declaration

    Swift

    @discardableResult
    func revive() -> Bool

    Return Value

    true if the tween is successfully revived.

Chaining Methods

  • ease(_:) Extension method

    Assigns a value to the ease property of the tween.

    Declaration

    Swift

    @discardableResult
    func ease(_ value: Ease) -> Tween

    Parameters

    value

    The Ease value to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • delay(_:) Extension method

    Assigns a value to the delay property of the tween.

    Declaration

    Swift

    @discardableResult
    func delay(_ value: TimeInterval) -> Tween

    Parameters

    value

    The amount of seconds to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • duration(_:) Extension method

    Assigns a value to the duration property of the tween.

    Declaration

    Swift

    @discardableResult
    func duration(_ value: TimeInterval) -> Tween

    Parameters

    value

    The amount of seconds to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onUpdate(_:) Extension method

    Assigns a value to the onUpdate property of the tween.

    Declaration

    Swift

    @discardableResult
    func onUpdate(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onStart(_:) Extension method

    Assigns a value to the onStart property of the tween.

    Declaration

    Swift

    @discardableResult
    func onStart(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onStop(_:) Extension method

    Assigns a value to the onStop property of the tween.

    Declaration

    Swift

    @discardableResult
    func onStop(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onRestart(_:) Extension method

    Assigns a value to the onRestart property of the tween.

    Declaration

    Swift

    @discardableResult
    func onRestart(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onPause(_:) Extension method

    Assigns a value to the onPause property of the tween.

    Declaration

    Swift

    @discardableResult
    func onPause(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onResume(_:) Extension method

    Assigns a value to the onResume property of the tween.

    Declaration

    Swift

    @discardableResult
    func onResume(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onComplete(_:) Extension method

    Assigns a value to the onComplete property of the tween.

    Declaration

    Swift

    @discardableResult
    func onComplete(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onKill(_:) Extension method

    Assigns a value to the onKill property of the tween.

    Declaration

    Swift

    @discardableResult
    func onKill(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

  • onRevive(_:) Extension method

    Assigns a value to the onRevive property of the tween.

    Declaration

    Swift

    @discardableResult
    func onRevive(_ callback: @escaping Callback) -> Tween

    Parameters

    value

    The callback closure to be assigned.

    Return Value

    The current tween to allow for additional customization.

Computed Properties

  • percentComplete Extension method

    The percentage of the tween’s elapsed time in relation to its duration specified in the range [0, 1].

    Declaration

    Swift

    public var percentComplete: Double { get }