🅿️Animatable
SwiftUI ⟩ animations ⟩ Animatable ⟩
Animatable describes how to animate a view with respect to some change in the view's data.
animatableData: required computed property (with default implementation by doing nothing)Shape conforms to Animatable
Use Animatable when you are unable to achieve the animation you want with animation(_:) or withAnimation(_:_:).
// ⭐️ 一維的 `animatableData`
var animatableData: CGFloat {
get { return sides }
set { sides = newValue } // ⭐️ set new animation value
}// ⭐️ 二維的 `animatableData` (AnimatablePair)
var animatableData: AnimatablePair<CGFloat, CGFloat> {
get { AnimatablePair(sides, scale) }
set { // ⭐️ set new animation value
sides = newValue.first
scale = newValue.second
}
}👉 see: Polygon
To expose two properties as animatable, wrap them in an AnimatablePair.
nest AnimatablePairs inside each other to support any number of properties.
To examine how SwiftUI interpolates between different values during an animation, we can add log statements to the setter of animatableData or the body method of the animatable modifier.
Vehicle - tap to animate.
MGE ⟩ animation - matched geometry effect.

QVIK ⟩ Basics of SwiftUI Animation #todo
Hacking with Swift ⟩ Customizing animations in SwiftUI
Big Mountain Studio ⟩ Trapezium - Part 3: Animating - animating Shape.
SwiftOnTap ⟩ Animatable ⭐️
SwiftUI Tutorials ⟩ Animating Views & Transitions ⟩
SwiftUI ⟩
Animatable (protocol)
animatableData - conforms to VectorArithmetic (protocol).
AnimatablePair (struct)
View ⟩ Graphics and Rendering ⟩
.animation(_:) - applied to equatable view
.animation(_:value:) - applied to equatable value (non-equatable view)
Animatable Modifiers is animatable.
Last updated
Was this helpful?