Wave.animate(withSpring:), you can animate multiple properties together within a single animation block.
Basic usage
The fundamental pattern is to callWave.animate(withSpring:) and modify view properties through the animator proxy:
API reference
TheWave.animate(withSpring:) method accepts several parameters:
The spring model that determines the timing curve and duration. See the Springs guide for choosing appropriate values.
Controls whether the animation block runs with animation or snaps immediately. Use
.nonAnimated to interrupt an existing animation and snap to new values.A delay in seconds before the animation starts.
The velocity from a gesture recognizer to inject into the animation. This creates smooth continuity when transitioning from gesture-driven to spring-driven motion.
A closure containing the property changes to animate. Must use the
animator property to modify values.A closure called when the animation finishes or retargets. The first parameter indicates if the animation finished, the second indicates if it was retargeted.
Animatable properties
UIView properties
These properties are available onview.animator:
CALayer properties
These properties are available onlayer.animator:
Multiple properties
You can animate multiple properties on different views in the same animation block. They will all use the same spring configuration:Animation modes
Themode parameter controls how the animation executes:
Animated mode (default)
Standard spring animation:Non-animated mode
Use.nonAnimated to interrupt a running animation and snap to the final value:
Simply setting
circle.center = ... directly won’t work because the animator will override it on the next frame. You must use the .nonAnimated mode.Delayed animations
Add a delay before the animation starts:Working with colors
Wave smoothly interpolates between colors:.clear will fade the alpha component while preserving other color components:
Real-world example
Here’s a complete example from Wave’s sample app that demonstrates multiple properties animating together:Best practices
Always use the animator property
Modify properties through
view.animator or layer.animator, never directly on the view or layer.Choose appropriate springs
Use
Spring.defaultAnimated for UI transitions and lower response values for interactive animations.Combine related changes
Group related property changes in a single animation block for synchronized motion.
Next steps
Property-based animations
Learn about the lower-level SpringAnimator API for more control
Gesture integration
Inject gesture velocities for fluid interactions
Completion handlers
Handle animation lifecycle events
Spring configuration
Master damping ratio and response values