Skip to main content
Spring determines the physical characteristics of spring animations, including how bouncy they are and how long they take to settle.

Overview

A Spring 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.
public init(
    dampingRatio: CGFloat,
    response: CGFloat,
    mass: CGFloat = 1.0
)
dampingRatio
CGFloat
required
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.
response
CGFloat
required
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.
mass
CGFloat
default:"1.0"
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.
public init(
    dampingRatio: CGFloat,
    stiffness: CGFloat,
    mass: CGFloat = 1.0
)
dampingRatio
CGFloat
required
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.
stiffness
CGFloat
required
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.
mass
CGFloat
default:"1.0"
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”).
public let dampingRatio: CGFloat

response

Represents the frequency response of the spring. This value affects how quickly the spring animation reaches its target value.
public let response: CGFloat

stiffness

The spring constant k. Used as an alternative to response.
public let stiffness: CGFloat

mass

The mass “attached” to the spring. The default value of 1.0 rarely needs to be modified.
public let mass: CGFloat

dampingCoefficient

The viscous damping coefficient c. This value is derived from other spring parameters.
public let dampingCoefficient: CGFloat

settlingDuration

The time the spring will take to settle or “complete”. This value is derived from other spring parameters.
public let settlingDuration: TimeInterval

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).
static public let defaultInteractive: Spring
Configured with dampingRatio: 0.8 and response: 0.20.

defaultAnimated

A reasonable, critically damped spring to use for non-interactive animations.
static public let defaultAnimated: Spring
Configured with dampingRatio: 1.0 and response: 0.82.

defaultNonAnimated

A placeholder spring to use when using the nonAnimated mode. See AnimationMode for more info.
static public let defaultNonAnimated: Spring
Configured with dampingRatio: 1.0 and response: 0.0.

Example usage

Creating a bouncy spring

let bouncySpring = Spring(dampingRatio: 0.5, response: 0.6)

Wave.animate(withSpring: bouncySpring) {
    view.animator.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
}

Creating a smooth spring

let smoothSpring = Spring(dampingRatio: 1.0, response: 0.4)

Wave.animate(withSpring: smoothSpring) {
    view.animator.alpha = 0.0
}

Using stiffness instead of response

let stiffSpring = Spring(dampingRatio: 0.7, stiffness: 200.0)

Wave.animate(withSpring: stiffSpring) {
    view.animator.center = targetPoint
}

Using default springs

// For interactive animations
Wave.animate(withSpring: .defaultInteractive) {
    draggedView.animator.center = finalPosition
}

// For standard UI animations
Wave.animate(withSpring: .defaultAnimated) {
    button.animator.backgroundColor = .systemBlue
}
Start with dampingRatio: 1.0 for smooth animations without bounce, or values between 0.5 and 0.8 for springy, bouncy animations.

Build docs developers (and LLMs) love