Learn Everything About SwiftUI Spring Animation

Learn Everything About SwiftUI Spring Animation

This post serves as a cheat sheet for building fine-grained and buttery motion/animations on iOS using predefined and custom springs. Check out the GitHub repo for about 100 SwiftUI spring animation examples, use cases, and best practices.


Get a Default Smooth Spring

withAnimation { }        


Article content

Use Spring Presets

Get smooth, snappy, and bouncy predefined springs

withAnimation(.smooth) { }        


Article content

Customize Spring Presets

Spring Preset With a Custom Duration

withAnimation(.snappy(duration: 0.4)) { }        


Article content


Spring Preset With a Custom Bounce

withAnimation(.snappy(extraBounce: 0.1)) { }        


Article content


Create a Custom Spring

withAnimation(.spring(duration: 0.6, bounce: 0.2)) { }        


Article content

Define a Custom Spring Model

let mySpring = Spring(duration: 0.5, bounce: 0.2) 
let (mass, stiffness, damping) = (mySpring.mass, mySpring.stiffness, mySpring.damping)        


Create a Spring Model Animation

let otherSpring = Spring(mass: 1, stiffness: 100, damping: 10) withAnimation(.spring(otherSpring)) { }        


Article content

Create a Spring With No Bounce

withAnimation(.spring(duration: 0.5)) { }        


Article content


Create a Spring With a Small Bounce

withAnimation(.spring(duration: 0.5, bounce: 0.15)) { }        


Article content


Create a Spring With a Large Bounce

withAnimation(.spring(duration: 0.5, bounce: 0.3)) { }        


Article content


Learn More

👉: https://github.com/GetStream/swiftui-spring-animations


Article content


مفيد للغاية

Like
Reply

To view or add a comment, sign in

Others also viewed

Explore topics