Spring

public class Spring : Equatable
extension Spring: CustomStringConvertible

Spring determines the timing curve and settling duration of an animation.

Springs are created by providing a dampingRatio greater than zero, and either a response or stiffness value. See the initializers init(dampingRatio:response:mass:) and init(dampingRatio:stiffness:mass:) for usage information.

Spring Properties

  • The amount of oscillation the spring will exhibit (i.e. “springiness”).

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public let mass: CGFloat
  • The viscous damping coefficient c. This value is derived.

    Declaration

    Swift

    public let dampingCoefficient: CGFloat
  • The time the spring will take to settle or “complete”. This value is derived.

    Declaration

    Swift

    public let settlingDuration: TimeInterval

Spring Initialization

  • Creates a spring with the given damping ratio and frequency response.

    Declaration

    Swift

    public init(dampingRatio: CGFloat, stiffness: CGFloat, mass: CGFloat = 1.0)

    Parameters

    dampingRatio

    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

    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

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

  • Creates a spring with the given damping ratio and frequency response.

    Declaration

    Swift

    public init(dampingRatio: CGFloat, response: CGFloat, mass: CGFloat = 1.0)

    Parameters

    dampingRatio

    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

    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

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

Default Springs

  • A reasonable, slightly underdamped spring to use for interactive animations (like dragging an item around).

    Declaration

    Swift

    public static let defaultInteractive: Spring
  • A reasonable, critically damped spring to use for non-interactive animations.

    Declaration

    Swift

    public static let defaultAnimated: Spring
  • A placeholder spring to use when using the nonAnimated mode. See AnimationMode for more info.

    Declaration

    Swift

    public static let defaultNonAnimated: Spring

Equatable

  • Declaration

    Swift

    public static func == (lhs: Spring, rhs: Spring) -> Bool
  • Declaration

    Swift

    public var description: String { get }