Spring determines the physical characteristics of spring animations, including how bouncy they are and how long they take to settle.
Overview
ASpring models the physics of a spring-mass-damper system. You can create springs using either a frequency response or a stiffness value, combined with a damping ratio.
Initializers
init(dampingRatio:response:mass:)
Creates a spring with the given damping ratio and frequency response.The amount of oscillation the spring will exhibit (i.e. “springiness”). A value of
1.0 (critically damped) will cause the spring to smoothly reach its target value without any oscillation. Values closer to 0.0 (underdamped) will increase oscillation (and overshoot the target) before settling.Represents the frequency response of the spring. This value affects how quickly the spring animation reaches its target value. The frequency response is the duration of one period in the spring’s undamped system, measured in seconds. Values closer to
0 create a very fast animation, while values closer to 1.0 create a relatively slower animation.The mass “attached” to the spring. The default value of
1.0 rarely needs to be modified.init(dampingRatio:stiffness:mass:)
Creates a spring with the given damping ratio and stiffness.The amount of oscillation the spring will exhibit (i.e. “springiness”). A value of
1.0 (critically damped) will cause the spring to smoothly reach its target value without any oscillation. Values closer to 0.0 (underdamped) will increase oscillation (and overshoot the target) before settling.Represents the spring constant,
k. This value affects how quickly the spring animation reaches its target value. Using stiffness values is an alternative to configuring springs with a response value.The mass “attached” to the spring. The default value of
1.0 rarely needs to be modified.Properties
dampingRatio
The amount of oscillation the spring will exhibit (i.e. “springiness”).response
Represents the frequency response of the spring. This value affects how quickly the spring animation reaches its target value.stiffness
The spring constantk. Used as an alternative to response.
mass
The mass “attached” to the spring. The default value of1.0 rarely needs to be modified.
dampingCoefficient
The viscous damping coefficientc. This value is derived from other spring parameters.
settlingDuration
The time the spring will take to settle or “complete”. This value is derived from other spring parameters.Default springs
Wave provides several pre-configured springs for common use cases:defaultInteractive
A reasonable, slightly underdamped spring to use for interactive animations (like dragging an item around).Configured with
dampingRatio: 0.8 and response: 0.20.defaultAnimated
A reasonable, critically damped spring to use for non-interactive animations.Configured with
dampingRatio: 1.0 and response: 0.82.defaultNonAnimated
A placeholder spring to use when using thenonAnimated mode. See AnimationMode for more info.
Configured with
dampingRatio: 1.0 and response: 0.0.