ios-animations
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesedot-skills — Airbnb iOS SwiftUI Animations Best Practices
dot-skills — Airbnb iOS SwiftUI 动画最佳实践
Opinionated, strict animation craft guide for SwiftUI iOS 26 / Swift 6.2 apps. Contains 50 rules across 8 categories, prioritized by impact. Derived from Airbnb Engineering motion patterns, Apple WWDC sessions, and Apple Human Interface Guidelines. Mandates @Equatable on every animated view, motion tokens for all spring/timing values, and design system tokens for layout.
这是一份针对SwiftUI iOS 26 / Swift 6.2应用的、具有明确立场的严格动画设计指南。包含8个类别共50条规则,按影响优先级排序。内容源自Airbnb工程团队的动效模式、Apple WWDC技术讲座及Apple人机界面指南。要求为每个动画视图添加@Equatable协议,所有弹簧/计时值使用动效令牌,布局使用设计系统令牌。
Mandated Architecture Alignment
强制架构对齐要求
This skill is designed to work alongside and . All code examples follow the same non-negotiable constraints:
swift-ui-architectios-design-system- macro on every view (Airbnb measured 15% scroll hitch reduction)
@Equatable - for complex animation state that involves business logic triggers
@Observable - for view-owned animation state (toggle booleans, drag offsets)
@State - Design system tokens: ,
Spacing.xs/sm/md/lg— zero hardcoded layout numbersRadius.sm/md/lg - Motion tokens: — zero scattered spring literals
Motion.standard/responsive/playful - Semantic colors: ,
.backgroundSurface— no raw Color literals in views.accentPrimary - Feature animations remain presentation-only; data/network concerns stay in Data package
本指南需与和配合使用。所有代码示例均遵循以下不可协商的约束:
swift-ui-architectios-design-system- 为每个视图添加宏(Airbnb数据显示可减少15%的滚动卡顿)
@Equatable - 涉及业务逻辑触发的复杂动画状态使用
@Observable - 视图自有动画状态(切换布尔值、拖拽偏移量)使用
@State - 设计系统令牌:、
Spacing.xs/sm/md/lg— 禁止使用硬编码布局数值Radius.sm/md/lg - 动效令牌:— 禁止分散使用弹簧字面量
Motion.standard/responsive/playful - 语义化颜色:、
.backgroundSurface— 视图中禁止使用原始Color字面量.accentPrimary - 功能模块的动画仅用于展示;数据/网络相关逻辑需保留在Data包内
Scope & Relationship to Sibling Skills
适用范围与关联技能的关系
This skill is the motion layer — it teaches how to BUILD fluid, performant animations. When loaded alongside sibling skills:
| Sibling Skill | Its Focus | This Skill's Focus |
|---|---|---|
| Architecture (modular MVVM-C, route shells, protocol boundaries) | Animation architecture (motion tokens, spring selection, orchestration) |
| Design system infrastructure (tokens, styles, governance) | Motion tokens and animated component patterns |
| HIG compliance patterns | Motion-specific HIG (reduce motion, spatial continuity) |
Out of scope: Designer-authored vector animations (use Lottie for After Effects exports). Complex UIKit transition controllers (see Airbnb's declarative transition framework). This skill covers programmatic SwiftUI animations only.
Clinic Architecture Contract (iOS 26 / Swift 6.2)
Clinic架构约定(iOS 26 / Swift 6.2)
All guidance in this skill assumes the clinic modular MVVM-C architecture:
- Feature modules import +
Domainonly (neverDesignSystem, never sibling features)Data - App target is the convergence point and owns , concrete coordinators, and Route Shell wiring
DependencyContainer - stays pure Swift and defines models plus repository,
Domain,*Coordinating, andErrorRoutingcontractsAppError - owns SwiftData/network/sync/retry/background I/O and implements Domain protocols
Data - Read/write flow defaults to stale-while-revalidate reads and optimistic queued writes
- ViewModels call repository protocols directly (no default use-case/interactor layer)
本指南的所有内容均基于Clinic模块化MVVM-C架构:
- 功能模块仅导入+
Domain(禁止导入DesignSystem或其他兄弟功能模块)Data - App目标是聚合点,负责、具体协调器及路由壳的连接
DependencyContainer - 层为纯Swift实现,定义模型及仓库、
Domain、*Coordinating和ErrorRouting协议AppError - 层负责SwiftData/网络/同步/重试/后台I/O,并实现Domain层协议
Data - 读写流程默认采用 stale-while-revalidate 读取策略和乐观队列写入策略
- ViewModel直接调用仓库协议(默认不使用用例/交互器层)
When to Apply
适用场景
Reference these guidelines when:
- Adding animations to SwiftUI views or transitions
- Building gesture-driven interactions (drag, swipe, pan)
- Connecting views with spatial transitions (expand/collapse, navigation morphs)
- Designing micro-interactions (button press, toggle, loading states)
- Making content changes feel physical (number rolls, symbol replacements)
- Choreographing multi-element animation sequences (KeyframeAnimator, PhaseAnimator)
- Defining motion tokens for a design system
- Reviewing animation code for performance, accessibility, and architecture compliance
在以下场景中参考本指南:
- 为SwiftUI视图或转场添加动画
- 构建手势驱动的交互(拖拽、滑动、平移)
- 使用空间转场连接视图(展开/折叠、导航形变)
- 设计微交互(按钮按压、切换、加载状态)
- 让内容变化具有物理质感(数字滚动、符号替换)
- 编排多元素动画序列(KeyframeAnimator、PhaseAnimator)
- 为设计系统定义动效令牌
- 评审动画代码的性能、无障碍访问及架构合规性
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix | Rules |
|---|---|---|---|---|
| 1 | Spring Physics | CRITICAL | | 8 |
| 2 | Timing & Feel | CRITICAL | | 6 |
| 3 | Gesture Continuity | HIGH | | 7 |
| 4 | Spatial Transitions | HIGH | | 6 |
| 5 | Micro-interactions | HIGH | | 6 |
| 6 | Orchestration | HIGH | | 5 |
| 7 | Craft & Polish | HIGH | | 5 |
| 8 | Content Motion | MEDIUM-HIGH | | 5 |
| 优先级 | 类别 | 影响级别 | 前缀 | 规则数量 |
|---|---|---|---|---|
| 1 | 弹簧物理 | CRITICAL | | 8 |
| 2 | 时序与质感 | CRITICAL | | 6 |
| 3 | 手势连续性 | HIGH | | 7 |
| 4 | 空间转场 | HIGH | | 6 |
| 5 | 微交互 | HIGH | | 6 |
| 6 | 动画编排 | HIGH | | 5 |
| 7 | 设计与打磨 | HIGH | | 5 |
| 8 | 内容动效 | MEDIUM-HIGH | | 5 |
Quick Reference
快速参考
1. Spring Physics (CRITICAL)
1. 弹簧物理(CRITICAL)
- — Define motion tokens as a caseless enum for all spring presets
spring-motion-tokens - — Default to .smooth spring for all UI transitions
spring-smooth-default - — Use .snappy spring for responsive interactions
spring-snappy-responsive - — Use .bouncy spring for playful and celebratory moments
spring-bouncy-celebration - — Tune custom springs with response and dampingFraction
spring-custom-parameters - — Springs preserve velocity on interruption
spring-velocity-preservation - — Never use linear or easeInOut for interactive UI
spring-never-linear - — Use withAnimation completion for chained sequences
spring-completion-chaining
- — 将所有弹簧预设的动效令牌定义为无值枚举
spring-motion-tokens - — 所有UI转场默认使用.smooth弹簧
spring-smooth-default - — 响应式交互使用.snappy弹簧
spring-snappy-responsive - — 趣味及庆祝场景使用.bouncy弹簧
spring-bouncy-celebration - — 通过response和dampingFraction调整自定义弹簧参数
spring-custom-parameters - — 弹簧动画在中断时保留速度
spring-velocity-preservation - — 交互式UI绝不使用线性或easeInOut动画
spring-never-linear - — 使用withAnimation的完成回调实现链式动画序列
spring-completion-chaining
2. Timing & Feel (CRITICAL)
2. 时序与质感(CRITICAL)
- — Keep UI animations under 250ms
feel-250ms-max - — Faster animations almost always feel better
feel-faster-better - — Use asymmetric timing for enter and exit
feel-asymmetric-enter-exit - — Match duration to distance traveled
feel-distance-proportional - — Sync haptic feedback to visual animation keyframes
feel-haptic-sync - — Stagger reveals at 30-50ms intervals
feel-stagger-timing
- — UI动画时长控制在250ms以内
feel-250ms-max - — 动画速度越快,体验通常越好
feel-faster-better - — 进入和退出动画使用非对称时序
feel-asymmetric-enter-exit - — 动画时长与移动距离成正比
feel-distance-proportional - — 触觉反馈与视觉动画关键帧同步
feel-haptic-sync - — 按30-50ms的间隔错开元素展示
feel-stagger-timing
3. Gesture Continuity (HIGH)
3. 手势连续性(HIGH)
- — Rubber band at drag boundaries
gesture-rubber-band - — Dismiss on velocity OR distance threshold
gesture-momentum-dismiss - — Use velocity-aware snap points
gesture-snap-points - — Make all gesture animations interruptible
gesture-interruptible - — Resolve scroll and drag gesture conflicts
gesture-scroll-drag-conflict - — Use GestureState for transient drag state
gesture-state-transient - — Project gesture velocity for natural landing position
gesture-projected-landing
- — 拖拽边界处添加橡皮筋效果
gesture-rubber-band - — 满足速度或距离阈值时触发关闭
gesture-momentum-dismiss - — 使用感知速度的吸附点
gesture-snap-points - — 所有手势动画需支持中断
gesture-interruptible - — 解决滚动与拖拽手势的冲突
gesture-scroll-drag-conflict - — 使用GestureState存储临时拖拽状态
gesture-state-transient - — 根据手势速度预测自然着陆位置
gesture-projected-landing
4. Spatial Transitions (HIGH)
4. 空间转场(HIGH)
- — Use matchedGeometryEffect for expand/collapse morphs
spatial-matched-geometry - — Use zoom navigation transition for collection detail (iOS 18)
spatial-zoom-navigation - — Anchor transitions to their trigger location
spatial-transition-origin - — Share multiple element IDs for rich hero animations
spatial-hero-shared-element - — Use matchedGeometryEffect for sheet presentations
spatial-sheet-morph - — Maintain spatial direction in tab transitions
spatial-tab-continuity
- — 使用matchedGeometryEffect实现展开/折叠形变
spatial-matched-geometry - — 集合详情页使用缩放导航转场(iOS 18)
spatial-zoom-navigation - — 将转场锚定到触发位置
spatial-transition-origin - — 共享多个元素ID实现丰富的英雄动画
spatial-hero-shared-element - — 使用matchedGeometryEffect实现弹窗展示动画
spatial-sheet-morph - — 标签切换转场保持空间方向一致性
spatial-tab-continuity
5. Micro-interactions (HIGH)
5. 微交互(HIGH)
- — Scale buttons to 0.97 on press for tactile feedback
micro-button-press-scale - — Pair every visual state change with haptic feedback
micro-haptic-pairing - — Use symbolEffect for SF Symbol animations
micro-symbol-effect - — Add bounce to toggle state changes
micro-toggle-bounce - — Animate progressive fill for long press actions
micro-long-press-fill - — Use repeating spring for organic loading states
micro-loading-phase
- — 按钮按压时缩放到0.97以提供触觉反馈
micro-button-press-scale - — 每个视觉状态变化都搭配触觉反馈
micro-haptic-pairing - — 使用symbolEffect实现SF Symbol动画
micro-symbol-effect - — 切换状态变化时添加弹跳效果
micro-toggle-bounce - — 长按操作时添加渐进填充动画
micro-long-press-fill - — 使用重复弹簧动画实现自然加载状态
micro-loading-phase
6. Orchestration (HIGH)
6. 动画编排(HIGH)
- — Use PhaseAnimator for multi-step sequences
orch-phase-animator - — Use KeyframeAnimator for timeline-precise motion
orch-keyframe-animator - — Stagger child elements for orchestrated reveals
orch-stagger-children - — Coordinate multi-element entrances with shared trigger
orch-coordinated-entrance - — Use TimelineView for continuous repeating animations
orch-timeline-view
- — 使用PhaseAnimator实现多步骤序列动画
orch-phase-animator - — 使用KeyframeAnimator实现时间线精确的动效
orch-keyframe-animator - — 错开子元素展示以实现编排式揭露效果
orch-stagger-children - — 通过共享触发器协调多元素入场动画
orch-coordinated-entrance - — 使用TimelineView实现持续重复动画
orch-timeline-view
7. Craft & Polish (HIGH)
7. 设计与打磨(HIGH)
- — Respect accessibilityReduceMotion with crossfade fallback
craft-reduce-motion - — Use blur to bridge imperfect transition states
craft-blur-bridge - — Use drawingGroup() for Metal-backed complex animations
craft-drawing-group - — Use geometryGroup() to isolate layout animation propagation
craft-geometry-group - — Use Transaction to debug and override animation behavior
craft-transaction-debug
- — 遵循accessibilityReduceMotion要求,提供淡入淡出 fallback 方案
craft-reduce-motion - — 使用模糊效果衔接不完善的转场状态
craft-blur-bridge - — 使用drawingGroup()实现基于Metal的复杂动画
craft-drawing-group - — 使用geometryGroup()隔离布局动画的传播
craft-geometry-group - — 使用Transaction调试和覆盖动画行为
craft-transaction-debug
8. Content Motion (MEDIUM-HIGH)
8. 内容动效(MEDIUM-HIGH)
- — Use contentTransition(.numericText) for number changes
content-numeric-text - — Use scrollTransition for scroll-position effects
content-scroll-transition - — Use visualEffect for position-aware animations
content-visual-effect - — Animate symbol replacement with contentTransition
content-symbol-replace - — Use Text Renderer for character-level animation (iOS 18)
content-text-renderer
- — 使用contentTransition(.numericText)实现数字变化动画
content-numeric-text - — 使用scrollTransition实现滚动位置相关效果
content-scroll-transition - — 使用visualEffect实现位置感知动画
content-visual-effect - — 使用contentTransition实现符号替换动画
content-symbol-replace - — 使用Text Renderer实现字符级动画(iOS 18)
content-text-renderer
How to Use
使用方法
Read individual reference files for detailed explanations with incorrect/correct code examples:
- Section definitions — Category structure and impact levels
- Rule template — Template for adding new rules
阅读单个参考文件获取包含错误/正确代码示例的详细说明:
- 章节定义 — 类别结构与影响级别
- 规则模板 — 添加新规则的模板
Reference Files
参考文件
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
| 文件 | 描述 |
|---|---|
| references/_sections.md | 类别定义与排序规则 |
| assets/templates/_template.md | 新规则模板 |
| metadata.json | 版本与参考信息 |