Animation
-
Manages the application of animations to a value.
See morelet 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)
Declaration
Swift
public final class Animator<Value> where Value : VectorConvertible
-
This class is used to drive a single animation to completion. It is one-shot, so a runner is no longer useful after the animation that it is driving completes.
- They begin in a
pending
state. - Then enter the
running
state afterstart()
is called. - If the animation finishes, the runner enters the
completed (finished)
state. - If
cancel()
is called on the runner while in a running state, the runner enters thecompleted (cancelled)
state.
import Advance let animation = 0.0.animation( to: 100.0, duration: 0.6, timingFunction: UnitBezier.easeIn) let runner = AnimationRunner(animation: animation) .onChange { value in /// Do something with the value. } .onCancel { /// The animation was cancelled before it could finish. } .onFinish { /// The animation finished successfully. } /// Kick off the animation runner.start()
The resulting runner can be used to cancel the animation or to add additional observers or completion handlers.
See moreDeclaration
Swift
public final class AnimationRunner<Value> where Value : VectorConvertible
- They begin in a
-
A protocol which defines the basic requirements to function as a time-advancable animation.
Conforming types can be used to animate values.
See moreDeclaration
Swift
public protocol Animation : Advanceable
-
Interpolates between values over a specified duration.
See moreDeclaration
Swift
public struct BasicAnimation<Value> : Animation where Value : VectorConvertible
Parameters
Value
The type of value to be animated.
-
A type-erased wrapper around an animation.
See moreDeclaration
Swift
public struct AnyAnimation<Value> : Animation where Value : VectorConvertible
-
An animation that is powered by a simulation function (e.g. a spring or decay function).
See moreDeclaration
Swift
public struct SimulatedAnimation<Value, T> : Animation where Value : VectorConvertible, T : SimulationFunction, Value.VectorType == T.VectorType