Animator
public final class Animator<Value> where Value : VectorConvertible
Manages the application of animations to a value.
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
let sizeAnimator = Animator(initialValue: view.bounds.size)
sizeAnimator.onChange = { view.bounds.size = $0 }
/// 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)
-
Called every time the animator’s
value
changes.Declaration
Swift
public var onChange: ((Value) -> Void)? { get set }
-
Initializes a new animator with the given value.
Declaration
Swift
public init(initialValue: Value)
-
assigning to this value will remove any running animation.
Declaration
Swift
public var value: Value { get set }
-
The current velocity of the animator.
Declaration
Swift
public var velocity: Value { get }
-
Animates the property using the given animation.
Declaration
Swift
public func animate(to finalValue: Value, duration: Double, timingFunction: TimingFunction = .swiftOut)
-
Animates the property using the given simulation function, imparting the specified initial velocity into the simulation.
Declaration
Swift
public func simulate<T>(using function: T, initialVelocity: T.Value) where Value == T.Value, T : SimulationFunction
-
Animates the property using the given simulation function.
Declaration
Swift
public func simulate<T>(using function: T) where Value == T.Value, T : SimulationFunction
-
Removes any active animation, freezing the animator at the current value.
Declaration
Swift
public func cancelRunningAnimation()