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(boundTo: view, keyPath: \.bounds.size)
/// 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)
-
Initializes a new property animator with the given target and keypath.
Declaration
Swift
public init(value: Value = Value.zero)
-
Convenience initializer that binds the animator to the given target object and key path. The current value of
object[keyPath: keyPath]
is used as the initial value of the animator.Declaration
Swift
public convenience init<T>(boundTo object: T, keyPath: ReferenceWritableKeyPath<T, Value>) where T: AnyObject
-
Animates the property using the given animation.
Declaration
Swift
public func animate<T>(with animation: T) -> AnimationRunner<Value> where T: Animation, T.Value == Value
-
Returns true if an animation is in progress.
Declaration
Swift
public var isAnimating: Bool
-
Cancels any running animation.
Declaration
Swift
public func cancelRunningAnimation()
-
assigning to this value will remove any running animation.
Declaration
Swift
public var value: Value
-
The current velocity of the value. Returns
Value.zero
if no animation is in progress.Declaration
Swift
public var velocity: Value
-
Starts a spring animation with the given properties, adopting the property’s current velocity as
initialVelocity
.Declaration
Swift
public func spring(to target: Value, tension: Scalar = 30.0, damping: Scalar = 5.0, threshold: Scalar = 0.1) -> AnimationRunner<Value>
-
Starts a spring animation with the given properties.
Declaration
Swift
public func spring(to target: Value, initialVelocity: Value, tension: Scalar = 30.0, damping: Scalar = 5.0, threshold: Scalar = 0.1) -> AnimationRunner<Value>
-
Undocumented
Declaration
Swift
public func animate(to finalValue: Value, duration: Double, timingFunction: TimingFunction = UnitBezier.swiftOut) -> AnimationRunner<Value>
-
Starts a decay animation with the current velocity of the property animator.
Declaration
Swift
public func decay(drag: Scalar = 3.0, threshold: Scalar = 0.1) -> AnimationRunner<Value>
-
Starts a decay animation with the given initial velocity.
Declaration
Swift
public func decay(initialVelocity: Value, drag: Scalar = 3.0, threshold: Scalar = 0.1) -> AnimationRunner<Value>
-
Declaration
Swift
public func observe(_ observer: @escaping (Value) -> Void) -> Subscription