Skip to main content

SwiftUI animation example

SwiftUI Spring Animation: Response and Bounce Compared

SwiftUI's .spring(response:dampingFraction:) and the newer .snappy, .smooth and .bouncy presets are easy to use but hard to picture. This demo runs three springs over the same distance at the same moment, so the differences are obvious: how fast each one gets there, and how much it overshoots.

  • 4.2 KB file
  • 5 live inputs
  • SwiftUI runtime
Live, try it

How this spring response comparison works

  • Each ball runs a spring with its own response and damping fraction, shown on its row.
  • Response is converted to stiffness the way SwiftUI does it: stiffness = (2π / response)².
  • Tap anywhere to send all three to the other side; "start" fires on each run.

Add it to your SwiftUI app

Install ExodeUI (Swift Package), download the file below, and paste this. The code updates as you customize. Other runtimes are in the other tabs.

import SwiftUI
import ExodeUI

// Add swiftui-spring-animation.exode to your app target (download it below).
struct SwiftuiSpringAnimationView: View {
  @StateObject private var controller = ExodeUIController()
  private let json = (try? String(contentsOf: Bundle.main.url(forResource: "swiftui-spring-animation", withExtension: "exode")!)) ?? "{}"

  var body: some View {
    ExodeUICanvas(
      artboardJson: json,
      fit: "Layout",
      controller: controller,
      onReady: { },
      onTrigger: { name, _ in
        // fires: 'start'
      }
    )
    .frame(height: 460)
  }
}

Inputs

InputTypeDefaultRange
responseNumber0.50.15 – 1.5
accentText#30d158hex colour
accent2Text#0a84ffhex colour
accent3Text#ff9f0ahex colour
bgText#000000hex colour

Events: start

More SwiftUI animations

The same idea in other frameworks: React shared element transition · React 3d flip card · React spring playground