Build fluid, interruptible Apple animations
Define the outcome
Create motion that explains a state change, preserves direct manipulation,
remains coherent when interrupted, adapts to accessibility settings, respects
the selected SDK and deployment target, and meets any claimed frame and power
budget.
Treat animation as a state transition rather than delayed visual side effects.
A compiling effect is incomplete when it snaps during retargeting, ignores
Reduce Motion, runs while hidden, or has not been exercised under interruption.
Read references selectively
- Read
references/methodology-and-motion-design.md before choosing whether to
animate, defining the motion contract, reviewing an implementation, or
selecting an API family.
- Read
references/interruption-and-velocity.md for gestures, retargeting,
reversal, springs, progress mapping, velocity continuity, or rapid input.
- Read
references/swiftui-state-and-transactions.md for withAnimation,
value-scoped .animation, Transaction, Animatable, completion, identity,
transitions, and matchedGeometryEffect.
- Read
references/swiftui-sequences-and-effects.md for phase or keyframe
choreography, content and symbol effects, scroll effects, Canvas,
TimelineView, shaders, or CustomAnimation.
- Read
references/uikit-property-animations.md for animation blocks,
constraints, UIViewPropertyAnimator, keyboard coordination, or UIKit
Dynamics.
- Read
references/navigation-transitions.md for SwiftUI navigation,
presentation, UIKit view-controller transitions, transition coordinators, or
mixed SwiftUI and UIKit flows.
- Read
references/appkit-and-cross-framework.md for AppKit animation contexts,
animator proxies, macOS Reduce Motion, or shared SwiftUI animation timing
across framework boundaries.
- Read
references/core-animation-and-frame-driving.md for CALayer,
CAAnimation, model and presentation layers, timing, CADisplayLink,
UIUpdateLink, or manual frame updates.
- Read
references/performance-and-diagnostics.md before diagnosing a hitch,
changing rendering groups, optimizing layout or effects, or making a
performance or power claim.
- Read
references/accessibility-and-availability.md for Reduce Motion,
cross-fade alternatives, autoplaying or repeating motion, API availability,
beta SDKs, and fallbacks.
- Read
references/testing-and-evidence.md before defining tests, profiling,
regression gates, production metrics, or completion evidence.
- Read
references/sources.md when behavior is SDK-sensitive, unfamiliar,
disputed, or needs a primary Apple source.
Repository instructions, product motion language, supported platforms, selected
SDK, deployment targets, and the user's requested scope override generic
examples. Never raise a deployment target or adopt beta-only behavior silently.
Route the request
Choose one lead mode:
- Explain or design: define purpose, states, interruption, accessibility,
mechanism, and evidence without editing.
- Implement or refactor: inspect the real state and ownership boundaries,
make the smallest lifecycle-complete change, and validate it.
- Review: report prioritized correctness, accessibility, availability, and
performance findings without fixing unless requested.
- Diagnose: reproduce the event sequence and localize the discontinuity or
missed frame before proposing a repair.
- Profile: for measurement-dependent tuning or a performance claim,
establish an equivalent scenario, record a baseline, change one supported
mechanism, and measure again.
- Test: exercise final states, interruption paths, accessibility variants,
device behavior, and performance thresholds.
In Implement or refactor mode, apply a safe, lifecycle-complete correction as
soon as state, ownership, timing, or API semantics prove it. Do not reduce it to
a recommendation because a profiler, Simulator, or physical device is
unavailable. Run available correctness checks and reserve profiling for
conditional tuning, quantification, and smoothness or power claims.
Lead with $swift-animation when motion behavior is the core problem. Use
$swiftui-optimization for broader invalidation or view-update architecture,
$app-performance for a whole-app investigation, $swift-concurrency for task
lifetime or cancellation, $voice-over-accessibility for semantic
accessibility, and $swift-rtl-support for directional layout or gestures.
Establish the motion contract
Before choosing an API:
- Name the functional purpose: status, spatial relationship, hierarchy,
continuity, feedback, or justified decoration.
- Define stable source and target states independently of the animation.
- Record every input that can arrive mid-flight: repeated tap, reverse drag,
new model state, navigation, resize, backgrounding, or disappearance.
- Decide whether the motion is noninteractive, interruptible, interactive, or
continuously retargetable.
- Define progress, completion and cancellation semantics, including the owner
and end condition of every animator, task, timer, and display update.
- Define position and velocity behavior when the target changes.
- Specify Reduce Motion and no-animation outcomes as complete UI states.
- Record platform, SDK, deployment target, refresh-rate assumptions, and the
evidence that will prove correctness and smoothness.
If motion has no user-facing purpose, prefer no animation.
Choose the lowest sufficient mechanism
Use this order:
- Prefer a system component, navigation transition, content transition, or
symbol effect when it expresses the intended relationship.
- Use state-driven SwiftUI animation or
UIView.animate for short,
fire-and-forget changes with stable endpoints.
- Use a spring and explicit state or
UIViewPropertyAnimator when input can
interrupt, reverse, scrub, or retarget the motion.
- Use phase or keyframe APIs for predetermined choreography whose timeline is
more important than arbitrary interruption.
- Use Core Animation for layer-specific timing, paths, groups, or compositing
behavior that higher-level APIs cannot express cleanly.
- Use
TimelineView, CADisplayLink, or UIUpdateLink only when content
genuinely depends on time or per-frame simulation.
Do not imitate interaction with a chain of delayed animations. Map gesture
progress directly to visual progress, then complete from the released position
and velocity.
Preserve continuity and ownership
- Keep one authoritative logical state; derive visual targets from it.
- Retarget from the current visual state rather than replaying from the old
endpoint.
- Preserve velocity for gesture-driven springs and normalize UIKit velocity
against the remaining displacement.
- Clamp progress only at intentional physical boundaries; keep raw gesture
translation available for rubber-banding or projected completion decisions.
- Cancel or supersede stale completion work when a newer transition wins.
- Scope SwiftUI animation to the state change that owns it. Do not attach a
broad
.animation high in the hierarchy.
- Reuse one interruptible animator for one UIKit transition context. Do not
manufacture a different animator on repeated framework callbacks.
- Update a Core Animation model layer to the final value when adding an
explicit animation; the animation object alone is not persistent state.
- Stop timers, display links, timeline schedules, and indefinite effects when
their content is static, hidden, backgrounded, or deallocated.
Build accessibility and availability in
Read Reduce Motion from the environment or accessibility API and react when it
changes. Replace large spatial movement, zoom, parallax, and indefinite motion
with a calmer transition, reduced amplitude, or no motion while preserving
state, focus, and task completion.
Check availability at the use site and provide a behaviorally complete
fallback. Treat APIs from prerelease SDKs as opt-in, isolated paths; verify
generated SDK interfaces and release notes rather than inferring availability
from a WWDC session or web page.
Diagnose and verify
Separate commit-phase work from render-phase work. Inspect state churn, layout,
main-thread work, decoding, and hierarchy mutation for commit hitches; inspect
offscreen passes, masks, blur, shadows, blending, rasterized surfaces, and
fill cost for render hitches.
Do not use average FPS or simulator appearance as sole evidence. Exercise rapid
reversal, repeated input, cancellation, Reduce Motion, background and
foreground, relevant refresh rates, and the slowest supported device class.
Profile representative Release builds on hardware when claiming smoothness,
power efficiency, or a fixed hitch.
Finish with the chosen mode, motion contract, framework and API, ownership and
interruption model, accessibility alternative, availability fallback, checks
and measurements run, device and build context, and remaining uncertainty.
1---2name: swift-animation3description: Use when designing, implementing, refactoring, reviewing, debugging, profiling, or testing animations and transitions in SwiftUI, UIKit, AppKit, or Core Animation across Apple platforms. Trigger for withAnimation, Animation, Transaction, Animatable, PhaseAnimator, KeyframeAnimator, matchedGeometryEffect, contentTransition, UIView.animate, UIViewPropertyAnimator, NSAnimationContext, view-controller transitions, CALayer or CAAnimation, springs, gesture-driven or interruptible motion, velocity continuity, system-transition coordination, CADisplayLink, UIUpdateLink, TimelineView, Reduce Motion, animation hitches, rendering or power cost, and animation regression tests. Do not use for RealityKit, Metal, SpriteKit, SceneKit, animated media content, or whole-app performance work where motion is only one symptom.4---56# Build fluid, interruptible Apple animations78## Define the outcome910Create motion that explains a state change, preserves direct manipulation,11remains coherent when interrupted, adapts to accessibility settings, respects12the selected SDK and deployment target, and meets any claimed frame and power13budget.1415Treat animation as a state transition rather than delayed visual side effects.16A compiling effect is incomplete when it snaps during retargeting, ignores17Reduce Motion, runs while hidden, or has not been exercised under interruption.1819## Read references selectively2021- Read `references/methodology-and-motion-design.md` before choosing whether to22 animate, defining the motion contract, reviewing an implementation, or23 selecting an API family.24- Read `references/interruption-and-velocity.md` for gestures, retargeting,25 reversal, springs, progress mapping, velocity continuity, or rapid input.26- Read `references/swiftui-state-and-transactions.md` for `withAnimation`,27 value-scoped `.animation`, `Transaction`, `Animatable`, completion, identity,28 transitions, and `matchedGeometryEffect`.29- Read `references/swiftui-sequences-and-effects.md` for phase or keyframe30 choreography, content and symbol effects, scroll effects, `Canvas`,31 `TimelineView`, shaders, or `CustomAnimation`.32- Read `references/uikit-property-animations.md` for animation blocks,33 constraints, `UIViewPropertyAnimator`, keyboard coordination, or UIKit34 Dynamics.35- Read `references/navigation-transitions.md` for SwiftUI navigation,36 presentation, UIKit view-controller transitions, transition coordinators, or37 mixed SwiftUI and UIKit flows.38- Read `references/appkit-and-cross-framework.md` for AppKit animation contexts,39 animator proxies, macOS Reduce Motion, or shared SwiftUI animation timing40 across framework boundaries.41- Read `references/core-animation-and-frame-driving.md` for `CALayer`,42 `CAAnimation`, model and presentation layers, timing, `CADisplayLink`,43 `UIUpdateLink`, or manual frame updates.44- Read `references/performance-and-diagnostics.md` before diagnosing a hitch,45 changing rendering groups, optimizing layout or effects, or making a46 performance or power claim.47- Read `references/accessibility-and-availability.md` for Reduce Motion,48 cross-fade alternatives, autoplaying or repeating motion, API availability,49 beta SDKs, and fallbacks.50- Read `references/testing-and-evidence.md` before defining tests, profiling,51 regression gates, production metrics, or completion evidence.52- Read `references/sources.md` when behavior is SDK-sensitive, unfamiliar,53 disputed, or needs a primary Apple source.5455Repository instructions, product motion language, supported platforms, selected56SDK, deployment targets, and the user's requested scope override generic57examples. Never raise a deployment target or adopt beta-only behavior silently.5859## Route the request6061Choose one lead mode:6263- **Explain or design**: define purpose, states, interruption, accessibility,64 mechanism, and evidence without editing.65- **Implement or refactor**: inspect the real state and ownership boundaries,66 make the smallest lifecycle-complete change, and validate it.67- **Review**: report prioritized correctness, accessibility, availability, and68 performance findings without fixing unless requested.69- **Diagnose**: reproduce the event sequence and localize the discontinuity or70 missed frame before proposing a repair.71- **Profile**: for measurement-dependent tuning or a performance claim,72 establish an equivalent scenario, record a baseline, change one supported73 mechanism, and measure again.74- **Test**: exercise final states, interruption paths, accessibility variants,75 device behavior, and performance thresholds.7677In Implement or refactor mode, apply a safe, lifecycle-complete correction as78soon as state, ownership, timing, or API semantics prove it. Do not reduce it to79a recommendation because a profiler, Simulator, or physical device is80unavailable. Run available correctness checks and reserve profiling for81conditional tuning, quantification, and smoothness or power claims.8283Lead with `$swift-animation` when motion behavior is the core problem. Use84`$swiftui-optimization` for broader invalidation or view-update architecture,85`$app-performance` for a whole-app investigation, `$swift-concurrency` for task86lifetime or cancellation, `$voice-over-accessibility` for semantic87accessibility, and `$swift-rtl-support` for directional layout or gestures.8889## Establish the motion contract9091Before choosing an API:92931. Name the functional purpose: status, spatial relationship, hierarchy,94 continuity, feedback, or justified decoration.952. Define stable source and target states independently of the animation.963. Record every input that can arrive mid-flight: repeated tap, reverse drag,97 new model state, navigation, resize, backgrounding, or disappearance.984. Decide whether the motion is noninteractive, interruptible, interactive, or99 continuously retargetable.1005. Define progress, completion and cancellation semantics, including the owner101 and end condition of every animator, task, timer, and display update.1026. Define position and velocity behavior when the target changes.1037. Specify Reduce Motion and no-animation outcomes as complete UI states.1048. Record platform, SDK, deployment target, refresh-rate assumptions, and the105 evidence that will prove correctness and smoothness.106107If motion has no user-facing purpose, prefer no animation.108109## Choose the lowest sufficient mechanism110111Use this order:1121131. Prefer a system component, navigation transition, content transition, or114 symbol effect when it expresses the intended relationship.1152. Use state-driven SwiftUI animation or `UIView.animate` for short,116 fire-and-forget changes with stable endpoints.1173. Use a spring and explicit state or `UIViewPropertyAnimator` when input can118 interrupt, reverse, scrub, or retarget the motion.1194. Use phase or keyframe APIs for predetermined choreography whose timeline is120 more important than arbitrary interruption.1215. Use Core Animation for layer-specific timing, paths, groups, or compositing122 behavior that higher-level APIs cannot express cleanly.1236. Use `TimelineView`, `CADisplayLink`, or `UIUpdateLink` only when content124 genuinely depends on time or per-frame simulation.125126Do not imitate interaction with a chain of delayed animations. Map gesture127progress directly to visual progress, then complete from the released position128and velocity.129130## Preserve continuity and ownership131132- Keep one authoritative logical state; derive visual targets from it.133- Retarget from the current visual state rather than replaying from the old134 endpoint.135- Preserve velocity for gesture-driven springs and normalize UIKit velocity136 against the remaining displacement.137- Clamp progress only at intentional physical boundaries; keep raw gesture138 translation available for rubber-banding or projected completion decisions.139- Cancel or supersede stale completion work when a newer transition wins.140- Scope SwiftUI animation to the state change that owns it. Do not attach a141 broad `.animation` high in the hierarchy.142- Reuse one interruptible animator for one UIKit transition context. Do not143 manufacture a different animator on repeated framework callbacks.144- Update a Core Animation model layer to the final value when adding an145 explicit animation; the animation object alone is not persistent state.146- Stop timers, display links, timeline schedules, and indefinite effects when147 their content is static, hidden, backgrounded, or deallocated.148149## Build accessibility and availability in150151Read Reduce Motion from the environment or accessibility API and react when it152changes. Replace large spatial movement, zoom, parallax, and indefinite motion153with a calmer transition, reduced amplitude, or no motion while preserving154state, focus, and task completion.155156Check availability at the use site and provide a behaviorally complete157fallback. Treat APIs from prerelease SDKs as opt-in, isolated paths; verify158generated SDK interfaces and release notes rather than inferring availability159from a WWDC session or web page.160161## Diagnose and verify162163Separate commit-phase work from render-phase work. Inspect state churn, layout,164main-thread work, decoding, and hierarchy mutation for commit hitches; inspect165offscreen passes, masks, blur, shadows, blending, rasterized surfaces, and166fill cost for render hitches.167168Do not use average FPS or simulator appearance as sole evidence. Exercise rapid169reversal, repeated input, cancellation, Reduce Motion, background and170foreground, relevant refresh rates, and the slowest supported device class.171Profile representative Release builds on hardware when claiming smoothness,172power efficiency, or a fixed hitch.173174Finish with the chosen mode, motion contract, framework and API, ownership and175interruption model, accessibility alternative, availability fallback, checks176and measurements run, device and build context, and remaining uncertainty.