Swiftui Spring Animations

Overview

Swiftui Spring Animations

This repository serves as your reference for SwiftUI Spring Animations. It demonstrates use cases for the various types of spring animations and their parameters. No more guessing the values for the parameters of spring animations you create for your next iOS app. Enjoy!!!

HSwiftUI spring animation parameters

A Chained Spring: Swift file

Chained Spring

A Bouncy Transition: Swift file

Bouncy Transition


SwiftUI Spring Animation Types

1 .spring()

A spring with no parameters. It applies gentle and sensible spring-feel to the object you want to animate.

Menu - Close icon transition: Swift file

Menu - Close icon

2 .interactiveSpring()

An interactive spring with no parameters. This creates a spring animation with a high stiffness and a low response. It creates a spring animation that is less snappy:

Menu - Close icon transition: Swift file

Menu - Close icon

3 .interpolatingSpring(stiffness, damping)

This allows you to create a spring animation that is based on stiffness and damping.

  • Stiffness: It is defined as the tensile strength of the spring. A higher stiffness will result in a snappier animation. This affects the force applied to the object
    and changes how quickly the object moves towards its target.
  • Damping: You can think of damping as the braking of a car or the back-drag frictional force of the surface the object is resting on. Its purpose is to stop the object over time. It also affects the ability to overshoot the object. Hint: Start with a damping of 15 and stiffness of 170. Reducing the
    damping to for example, 5 will create a spring animation that has a higher bounciness.

Chat message reactions: Swift file

Chat message reactions

4 .interpolatingSpring(mass, stiffness, damping, initialVelocity)

This allows you to create a spring animation that is based on mass, stiffness, damping, and initial velocity. Default values: .interpolatingSpring (mass: Double = 1.0, stiffness: Double, damping: Double, initialVelocity: Double = 0.0).

  • Mass: Think of mass as the weight of the object animating. It changes the inertial of the object attached to the spring. That is the willingness of an object to move or stop moving. It is conceptually heavier and can be used to create a spring animation that overshoots. The heavier the mass, the longer it takes to move the object, speed it up, and slow it down.
  • Initial Velocity: The initial velocity defines the speed at which the animation object changes at the beginning of the animation. The default initial velocity is set to zero. It is measured in units per second of the animation.

Chat message reactions (Heart icon): Swift file

Chat message reactions

5 .spring(response, dampingFraction, blendDuration)

This allows you to create a spring animation that is based on response, damping fraction, and blend duration. Default values: .spring (response: Double = 0.55, dampingFraction: Double = 0.825, blendDuration: Double = 0). A higher response value will slow the down the animation. A lower response speeds it up.

  • Response: It controls how quickly an animating property value will try and get to a target. You can use the response to create an infinitely-stiff spring by setting its value to zero.

  • Damping Fraction: Damping fraction causes a gradual reduction in a spring oscillation. By using the damping fraction, you can define how rapidly the
    oscillations decay from one bounce to the next. You can damp the spring in the following ways:

    Chat message reactions

    • Over Damping: Set the damping fraction to a value greater than 1. It lets the object you are animating, quickly return to the rest position.
    • Critical Damping: Set the damping fraction = 1. It lets the object return to the rest position within the shortest amount of time.
    • Under Damping: Set the damping fraction to be less than 1. It lets the object overshoot multiple times passing the rest position and gradually reaching the rest position.
    • Undamped: Set the damping fraction = 0. It lets the object oscillate forever.
  • Blend Duration: Blend duration is a frame of time during which a previous animation stops and the next animation starts. Changing the blend duration of any the examples here, does not produce any visual change. This makes it difficult to see what it actually does.

Chat message reactions (Thumbs up icon): Swift file

Chat message reactions

6 .interactiveSpring(response, dampingFraction, blendDuration)

This allows you to create a spring animation that is based on response, damping fraction, and blend duration. Default values: interactiveSpring (response: Double = 0.15, dampingFraction: Double = 0.86, blendDuration: Double = 0.25). You can use this spring as an alternative to .spring(response, dampingFraction, blendDuration). Always start with the default values above. To check the default values in XCode, Control-click the spring modifier and select "Show Quick Help". The thumbs down animation below uses this spring. The damping fraction is inversely proportioan to the springiness of the animation. Reducing the default damping fraction will make the animation more bouncier. As mentioned in 5 above, blend duration has not visible effect on the spring, at the time of writing this.

Chat message reactions (Thumbs down icon): Swift file

Chat message reactions


SwiftUI Spring Animation Properties and Effects

Damping Fraction: High, medium, low, and no bounce

Swift file Damping Fraction

Stiffness Bounce: High, low, medium, and very low stiffness

Swift file Stiffness Bounc

Varying Stiffness and Damping: Stiff, gentle, wobble, and no wobble

Swift file Damping Fraction


SwiftUI Spring Animation Examples

Position Spring Animation:

Animate a ball's position so that it appears to be pulled towards a target by a spring. Swift file Position Spring Animation

Scale Spring Animation:

Create a spring animation that bounces a ball into view by animating its scale from 1 to 2. Swift file Scale Spring Animation

Recording Spring Animation:

Create a recording effect using different springs. Swift file Create a recording effect using different springs.

Animate a photo preview to its fill view

Swift file  Animate a photo preview to full view

Zoom a photo from its gallery

Swift file  Zoom a photo from gallery

Animate a photo from its fit view to a fullscreen view

Swift file  Animate a photo from its fit view to a fullscreen view

Animate a ball to fall and bounce

Swift file Animate a ball to fall and bounce

Animate a bell to rotate with springiness

Swift file Animate a bell to rotate with springiness


** Related Links **

You might also like...
LottieView - Wrapper around Lottie in SwiftUI that allows chaining animations & triggering callbacks at certain frames

LottieView is a Wrapper around Lottie in SwiftUI that allows chaining animations & triggering callbacks at certain frames

Easily pause and resume SwiftUI animations
Easily pause and resume SwiftUI animations

swiftui-pausable-animation Easily pause and resume SwiftUI animations! Installation This component is distributed as a Swift package. Just add this re

Compose SpriteKit animations quickly in a declarative SwiftUI-style

ActionBuilder Caveat developer: As this package is pre-release, the API may change significantly without notice. It has not been tested, so use it at

A concept to more easily define simple keyframe / multi-step animations in SwiftUI

🎞 Animate A concept to more easily define simple keyframe / multi-step animations in SwiftUI, without: Defining an @State value for each property to

Physics-based animations for iOS, tvOS, and macOS.

Advance An animation library for iOS, tvOS, and macOS that uses physics-based animations (including springs) to power interactions that move and respo

Advanced Natural Motion Animations, Simple Blocks Based Syntax
Advanced Natural Motion Animations, Simple Blocks Based Syntax

FlightAnimator Moved to Swift 3.1 Support: For Swift 3.1 - Use tag Version 0.9.9 See Installation Instructions for clarification Introduction FlightAn

Swift interpolation for gesture-driven animations
Swift interpolation for gesture-driven animations

Interpolate Interpolate is a powerful Swift interpolation framework for creating interactive gesture-driven animations. Usage The 🔑 idea of Interpola

An iOS library to natively render After Effects vector animations
An iOS library to natively render After Effects vector animations

Lottie for iOS, macOS (and Android and React Native) View documentation, FAQ, help, examples, and more at airbnb.io/lottie Lottie is a mobile library

A library to simplify iOS animations in Swift.

Updated for Swift 4.2 Requires Xcode 10 and Swift 4.2. Installation Drop in the Spring folder to your Xcode project (make sure to enable "Copy items i

Owner
Stream
Build scalable newsfeeds, activity streams, chat and messaging in a few hours instead of weeks
Stream
Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers. It's magic. Features Animate a

Robert-Hein Hooijmans 1.3k Nov 17, 2022
Wave is a spring-based animation engine for iOS that makes it easy to create fluid, interruptible animations that feel great.

Wave is a spring-based animation engine for iOS and iPadOS. It makes it easy to create fluid, interactive, and interruptible animations that feel great.

Janum Trivedi 1.2k Jan 8, 2023
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

Marin Todorov 3k Dec 27, 2022
Aplikacja realizowana w ramach rekrutacji na staż Allegro Spring TECH e-Xperience 2022

RepoFinderAllegro Aplikacja realizowana w ramach rekrutacji na staż Allegro Spring TECH e-Xperience 2022 Uruchamianie Do uruchomienia aplikacji potrze

null 0 Jan 9, 2022
A collection of animations for iOS. Simple, just add water animations.

DCAnimationKit A collection of animations for iOS Simply, just add water! DCAnimationKit is a category on UIView to make animations easy to perform. E

Dalton 797 Sep 23, 2022
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
Animations created with SwiftUI.

A repository containing a variety of animations and Animated components created in SwiftUI that you can use in your own projects.

Shubham Kr. Singh 1.5k Jan 2, 2023
Match animations in SwiftUI and UIKit/AppKit

MatchedAnimation Match animations in SwiftUI and UIKit/AppKit. /// Draw a box in

Ryan Carver 6 Dec 21, 2022
Tools for SwiftUI that helps perform Path and Shape animations, such us morphing circle or shape transformations

SwiftUI+PathAnimations ?? Introduction This packages contains SimilarShape and InterpolatedShape, both can be used to achieve shapes animations with S

Alfredo Delli Bovi 180 Dec 29, 2022