Tween
public protocol Tween : AnyObject
A handle that provides state control and customization of a tween animation.
-
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 tween’s current state, i.e., active, paused, etc.
Declaration
Swift
var state: TweenState { get }
-
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 }
-
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 }
-
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
delayedstate, the elapsed delay is updated instead; otherwise, the tween can only be updated if in anactivestate.Declaration
Swift
@discardableResult func update(by deltaTime: TimeInterval) -> BoolParameters
deltaTimeThe amount of seconds passed since the last update.
Return Value
trueif the tween is successfully updated. -
Starts the tween for updates, putting it in an
activestate from its beginning values. The tween can only be started if it’s in aneworinactivestate.Declaration
Swift
@discardableResult func start() -> BoolReturn Value
trueif the tween is successfully started. -
Stops the tween from updating, putting it in an
inactivestate. The tween can only be stopped if it’s in anactive,delayed, orpausedstate.Declaration
Swift
@discardableResult func stop() -> BoolReturn Value
trueif 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
killedstate.Declaration
Swift
@discardableResult func restart() -> BoolReturn Value
trueif the tween is successfully restarted. -
Pauses the tween, maintaining its current progress. The tween can only be paused if it’s in an
activeordelayedstate.Declaration
Swift
@discardableResult func pause() -> BoolReturn Value
trueif 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
pausedstate.Declaration
Swift
@discardableResult func resume() -> BoolReturn Value
trueif 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
completestate and not in akilledstate. The tween will automatically be killed ifDefaults.autoKillCompletedTweensistrue.Declaration
Swift
@discardableResult func complete() -> BoolReturn Value
trueif 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 akilledstate.Declaration
Swift
@discardableResult func kill() -> BoolReturn Value
trueif the tween is successfully killed. -
Revives the tween, putting it in a
newstate, and re-adds it toTweener‘s list of tracked tweens. The tween can only be revived if it’s in akilledstate.Declaration
Swift
@discardableResult func revive() -> BoolReturn Value
trueif the tween is successfully revived.
-
ease(_:)Extension method -
delay(_:)Extension methodAssigns a value to the
delayproperty of the tween.Declaration
Swift
@discardableResult func delay(_ value: TimeInterval) -> TweenParameters
valueThe amount of seconds to be assigned.
Return Value
The current tween to allow for additional customization.
-
duration(_:)Extension methodAssigns a value to the
durationproperty of the tween.Declaration
Swift
@discardableResult func duration(_ value: TimeInterval) -> TweenParameters
valueThe amount of seconds to be assigned.
Return Value
The current tween to allow for additional customization.
-
onUpdate(_:)Extension method -
onStart(_:)Extension method -
onStop(_:)Extension method -
onRestart(_:)Extension method -
onPause(_:)Extension method -
onResume(_:)Extension method -
onComplete(_:)Extension methodAssigns a value to the
onCompleteproperty of the tween.Declaration
Swift
@discardableResult func onComplete(_ callback: @escaping Callback) -> TweenParameters
valueThe callback closure to be assigned.
Return Value
The current tween to allow for additional customization.
-
onKill(_:)Extension method -
onRevive(_:)Extension method
-
percentCompleteExtension method
View on GitHub
Tween Protocol Reference