Contents

Spring

A representation of a spring’s motion.

Declaration

struct Spring

Overview

Use this type to convert between different representations of spring parameters:

let spring = Spring(duration: 0.5, bounce: 0.3)
let (mass, stiffness, damping) = (spring.mass, spring.stiffness, spring.damping)
// (1.0, 157.9, 17.6)

let spring2 = Spring(mass: 1, stiffness: 100, damping: 10)
let (duration, bounce) = (spring2.duration, spring2.bounce)
// (0.63, 0.5)

You can also use it to query for a spring’s position and its other properties for a given set of inputs:

func unitPosition(time: TimeInterval) -> Double {
    let spring = Spring(duration: 0.5, bounce: 0.3)
    return spring.position(target: 1.0, time: time)
}

Topics

Creating a spring

Getting built-in springs

Getting spring characteristics

Getting spring state

Setting spring state

Calculating forces and durations

See Also

Creating custom animations