Spring
public final class Spring<T: VectorConvertible>
Animates changes to a value using spring physics.
Instances of Spring
should be used in situations where spring physics
are the only animation type required, or when convenient access to the
properties of a running spring simulation is needed.
The focused API of this class makes it more convenient in such cases
than using an Animatable
instance, where a new spring animation would
have to be added each time the spring needed to be modified.
let s = Spring(value: CGPoint.zero)
s.changed.observe { (value) in
// do something with the value when it changes
}
s.target = CGPoint(x: 100.0, y: 200.0)
// Off it goes!
-
Creates a new
Spring
instanceDeclaration
Swift
public init(value: T)
Parameters
value
-
Removes any current velocity and snaps the spring directly to the given value.
Declaration
Swift
public func reset(_ value: T)
-
The current value of the spring.
Declaration
Swift
public var value: T
-
The current velocity of the simulation.
Declaration
Swift
public var velocity: T
-
The target value of the spring. As the simulation runs,
value
will be pulled toward this value.Declaration
Swift
public var target: T
-
Configuration options for the spring.
Declaration
Swift
public var configuration: SpringConfiguration