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
delayed
state, the elapsed delay is updated instead; otherwise, the tween can only be updated if in anactive
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 anew
orinactive
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 anactive
,delayed
, orpaused
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
ordelayed
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 akilled
state. The tween will automatically be killed ifDefaults.autoKillCompletedTweens
istrue
.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 akilled
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 toTweener
‘s list of tracked tweens. The tween can only be revived if it’s in akilled
state.Declaration
Swift
@discardableResult func revive() -> Bool
Return Value
true
if the tween is successfully revived.
-
ease(_:)
Extension method -
delay(_:)
Extension methodAssigns 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 methodAssigns 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 -
onStart(_:)
Extension method -
onStop(_:)
Extension method -
onRestart(_:)
Extension method -
onPause(_:)
Extension method -
onResume(_:)
Extension method -
onComplete(_:)
Extension methodAssigns 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 -
onRevive(_:)
Extension method
-
percentComplete
Extension method