emilkowal-animations-swift
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSwiftUI & AppKit Animation Best Practices
SwiftUI & AppKit 动画最佳实践
Comprehensive animation guide for Apple platform interfaces, adapted from Emil Kowalski's web animation principles and Framer Motion best practices. Contains 80 rules across 10 categories targeting iOS 17+, prioritized by impact.
这是一份针对苹果平台界面的综合动画指南,改编自Emil Kowalski的Web动画原则和Framer Motion最佳实践。包含针对iOS 17+的10个类别共80条规则,按影响优先级排序。
When to Apply
适用场景
Reference these guidelines when:
- Adding animations to SwiftUI views
- Choosing easing curves, springs, or timing values
- Implementing gesture-based interactions (drag, tap, long press)
- Building transitions and navigation animations
- Using for shared element transitions
matchedGeometryEffect - Creating scroll-linked or parallax effects
- Using iOS 17+ or
PhaseAnimatorKeyframeAnimator - Optimizing animation performance
- Ensuring animation accessibility with
accessibilityReduceMotion - Writing AppKit/macOS-specific animations
在以下场景中可参考本指南:
- 为SwiftUI视图添加动画
- 选择缓动曲线、弹簧效果或时间参数
- 实现基于手势的交互(拖拽、点击、长按)
- 构建转场与导航动画
- 使用实现共享元素转场
matchedGeometryEffect - 创建滚动联动或视差效果
- 使用iOS 17+的或
PhaseAnimatorKeyframeAnimator - 优化动画性能
- 通过确保动画的可访问性
accessibilityReduceMotion - 编写AppKit/macOS专属动画
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Timing Curves & Easing | CRITICAL | |
| 2 | Duration & Timing | CRITICAL | |
| 3 | Animation Properties | HIGH | |
| 4 | Transforms & Effects | HIGH | |
| 5 | Gesture & Interaction | HIGH | |
| 6 | Transitions & Navigation | MEDIUM-HIGH | |
| 7 | Scroll & Parallax | MEDIUM | |
| 8 | Strategic Animation | MEDIUM | |
| 9 | Accessibility & Polish | MEDIUM | |
| 10 | AppKit Specific | LOW-MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 时间曲线与缓动 | 关键 | |
| 2 | 时长与时序 | 关键 | |
| 3 | 动画属性 | 高 | |
| 4 | 变换与效果 | 高 | |
| 5 | 手势与交互 | 高 | |
| 6 | 转场与导航 | 中高 | |
| 7 | 滚动与视差 | 中 | |
| 8 | 动画策略 | 中 | |
| 9 | 可访问性与优化 | 中 | |
| 10 | AppKit专属 | 中低 | |
Quick Reference
快速参考
1. Timing Curves & Easing (CRITICAL)
1. 时间曲线与缓动(关键)
- - Use easeOut as your default easing
ease-prefer-easeout - - Avoid linear easing for UI animations
ease-avoid-linear - - Prefer springs for natural motion
ease-spring-default - - Use iOS 17 Spring struct with bounce/duration
ease-spring-ios17 - - Create custom curves with timingCurve
ease-custom-timing-curve - - Use easeIn for exit animations
ease-ease-in-for-exits - - Use easeInOut for emphasis motion
ease-ease-inout-for-emphasis - - Configure spring response for duration feel
ease-spring-response - - Configure spring damping for bounce
ease-spring-damping - - Match easing to animation context
ease-match-context
- - 默认使用easeOut缓动
ease-prefer-easeout - - UI动画避免使用线性缓动
ease-avoid-linear - - 优先选择弹簧效果实现自然动效
ease-spring-default - - 使用iOS 17的Spring结构体配置弹跳/时长
ease-spring-ios17 - - 用timingCurve创建自定义曲线
ease-custom-timing-curve - - 退出动画使用easeIn缓动
ease-ease-in-for-exits - - 强调动效使用easeInOut缓动
ease-ease-inout-for-emphasis - - 配置弹簧响应参数调整时长感受
ease-spring-response - - 配置弹簧阻尼参数调整弹跳程度
ease-spring-damping - - 缓动效果需匹配动画场景
ease-match-context
2. Duration & Timing (CRITICAL)
2. 时长与时序(关键)
- - Use 200ms as default UI animation duration
timing-200ms-default - - Use 100ms for micro-interactions
timing-100ms-micro - - Keep emphasis animations under 300ms
timing-300ms-emphasis - - Stagger child animations for orchestration
timing-stagger-children - - Use delay strategically for sequencing
timing-delay-strategic
- - UI动画默认时长设为200ms
timing-200ms-default - - 微交互动画使用100ms时长
timing-100ms-micro - - 强调动画时长控制在300ms以内
timing-300ms-emphasis - - 子元素动画使用 stagger 实现编排
timing-stagger-children - - 合理使用延迟实现动画序列
timing-delay-strategic
3. Animation Properties (HIGH)
3. 动画属性(高)
- - Prefer opacity and scale for performance
props-opacity-scale - - Avoid animating frame size directly
props-avoid-size-animate - - Set anchor points for transforms
props-transform-origin - - Use drawingGroup for complex hierarchies
props-drawing-group - - Use animation(nil) to prevent animations
props-animation-disable - - Use withAnimation for explicit control
props-explicit-animation - - Use .animation modifier for implicit animations
props-implicit-animation
- - 优先使用透明度和缩放提升性能
props-opacity-scale - - 避免直接对帧尺寸做动画
props-avoid-size-animate - - 为变换设置锚点
props-transform-origin - - 复杂层级使用drawingGroup
props-drawing-group - - 使用animation(nil)禁用动画
props-animation-disable - - 使用withAnimation实现显式控制
props-explicit-animation - - 使用.animation修饰符实现隐式动画
props-implicit-animation
4. Transforms & Effects (HIGH)
4. 变换与效果(高)
- - Use subtle scale values (0.95-0.98)
transform-scale-subtle - - Apply rotation with purpose
transform-rotation-purposeful - - Translate in meaningful directions
transform-translate-direction - - Use rotation3DEffect for depth
transform-3d-perspective - - Modifier order affects output
transform-order-matters - - Set anchor for rotation/scale origin
transform-anchor-point - - Combine transforms purposefully
transform-combine-effects
- - 使用细微缩放值(0.95-0.98)
transform-scale-subtle - - 有目的性地应用旋转
transform-rotation-purposeful - - 按有意义的方向进行位移
transform-translate-direction - - 使用rotation3DEffect实现深度感
transform-3d-perspective - - 修饰符顺序会影响输出结果
transform-order-matters - - 为旋转/缩放设置原点锚点
transform-anchor-point - - 有目的性地组合多种变换
transform-combine-effects
5. Gesture & Interaction (HIGH)
5. 手势与交互(高)
- - Provide immediate tap feedback
gesture-tap-feedback - - Animate long press states
gesture-long-press - - Implement smooth drag interactions
gesture-drag-basic - - Constrain drag within bounds
gesture-drag-constraints - - Use velocity for momentum effects
gesture-drag-velocity - - Use @GestureState for transient values
gesture-gesture-state - - Use .updating for live feedback
gesture-updating-modifier - - Choose gesture composition
gesture-simultaneous-vs-exclusive - - Implement pinch-to-zoom
gesture-magnify-gesture - - Implement rotation gestures
gesture-rotation-gesture - - Handle hover on macOS
gesture-hover-macos - - Pair gestures with haptics
gesture-sensory-feedback - - Spring back on gesture end
gesture-spring-on-release - - Handle gesture cancellation gracefully
gesture-cancellation
- - 提供即时的点击反馈
gesture-tap-feedback - - 为长按状态添加动画
gesture-long-press - - 实现流畅的拖拽交互
gesture-drag-basic - - 限制拖拽范围在边界内
gesture-drag-constraints - - 利用速度实现动量效果
gesture-drag-velocity - - 使用@GestureState存储临时值
gesture-gesture-state - - 使用.updating实现实时反馈
gesture-updating-modifier - - 选择合适的手势组合方式
gesture-simultaneous-vs-exclusive - - 实现捏合缩放
gesture-magnify-gesture - - 实现旋转手势
gesture-rotation-gesture - - 在macOS上处理悬停事件
gesture-hover-macos - - 为手势搭配触觉反馈
gesture-sensory-feedback - - 手势结束时使用弹簧效果复位
gesture-spring-on-release - - 优雅处理手势取消
gesture-cancellation
6. Transitions & Navigation (MEDIUM-HIGH)
6. 转场与导航(中高)
- - Use built-in transition types
transition-builtin-types - - Use asymmetric for different enter/exit
transition-asymmetric - - Combine transitions for richer effects
transition-combined - - Create custom transition modifiers
transition-custom-modifier - - Use matchedGeometryEffect properly
transition-matched-geometry - - Manage @Namespace lifecycle
transition-namespace-scope - - Customize navigation transitions
transition-navigation-transitions - - Animate sheet presentations
transition-sheet-presentations - - Use .id() for view replacement
transition-id-for-replacement - - Use contentTransition for text
transition-content-transition
- - 使用内置转场类型
transition-builtin-types - - 为进入/退出使用不对称转场
transition-asymmetric - - 组合多种转场实现更丰富的效果
transition-combined - - 创建自定义转场修饰符
transition-custom-modifier - - 正确使用matchedGeometryEffect
transition-matched-geometry - - 管理@Namespace生命周期
transition-namespace-scope - - 自定义导航转场
transition-navigation-transitions - - 为弹窗展示添加动画
transition-sheet-presentations - - 使用.id()实现视图替换动画
transition-id-for-replacement - - 为文本使用contentTransition
transition-content-transition
7. Scroll & Parallax (MEDIUM)
7. 滚动与视差(中)
- - Use GeometryReader for scroll position
scroll-geometry-reader - - Use PreferenceKey for scroll data
scroll-preference-key - - Create parallax scroll effects
scroll-parallax-effect - - Implement animated sticky headers
scroll-sticky-header - - Use iOS 17 scrollTransition modifier
scroll-scroll-transition - - Use iOS 17 visualEffect modifier
scroll-visual-effect
- - 使用GeometryReader获取滚动位置
scroll-geometry-reader - - 使用PreferenceKey获取滚动数据
scroll-preference-key - - 创建滚动视差效果
scroll-parallax-effect - - 实现带动画的粘性头部
scroll-sticky-header - - 使用iOS 17的scrollTransition修饰符
scroll-scroll-transition - - 使用iOS 17的visualEffect修饰符
scroll-visual-effect
8. Strategic Animation (MEDIUM)
8. 动画策略(中)
- - Every animation needs purpose
strategy-purposeful-motion - - Use motion to show hierarchy
strategy-hierarchy-emphasis - - Animate state changes clearly
strategy-state-communication - - Maintain spatial relationships
strategy-spatial-continuity - - Express brand through motion
strategy-brand-expression
- - 每一个动画都要有明确目的
strategy-purposeful-motion - - 用动效展示层级关系
strategy-hierarchy-emphasis - - 通过动画清晰展示状态变化
strategy-state-communication - - 保持空间关系的连续性
strategy-spatial-continuity - - 通过动效传递品牌调性
strategy-brand-expression
9. Accessibility & Polish (MEDIUM)
9. 可访问性与优化(中)
- - Respect accessibilityReduceMotion
polish-reduce-motion - - Use PhaseAnimator for sequences
polish-phase-animator - - Use KeyframeAnimator for complex paths
polish-keyframe-animator - - Handle animation completion
polish-animation-completions - - Make animations interruptible
polish-interruptible-animations - - Debug animations effectively
polish-animation-debugging - - Profile animation performance
polish-performance-profiling - - Use SF Symbol effects
polish-symbol-effects - - Animate text with contentTransition
polish-text-animations - - Pair animations with haptic feedback
polish-haptic-pairing
- - 尊重accessibilityReduceMotion设置
polish-reduce-motion - - 使用PhaseAnimator实现序列动画
polish-phase-animator - - 使用KeyframeAnimator实现复杂路径动画
polish-keyframe-animator - - 处理动画完成事件
polish-animation-completions - - 让动画可被中断
polish-interruptible-animations - - 高效调试动画
polish-animation-debugging - - 分析动画性能
polish-performance-profiling - - 使用SF Symbol效果
polish-symbol-effects - - 用contentTransition为文本添加动画
polish-text-animations - - 为动画搭配触觉反馈
polish-haptic-pairing
10. AppKit Specific (LOW-MEDIUM)
10. AppKit专属(中低)
- - Use NSAnimationContext for grouping
appkit-nsanimation-context - - Use Core Animation layers
appkit-core-animation - - Enable layer backing for performance
appkit-layer-backed-views - - Leverage implicit layer animations
appkit-implicit-animations - - Create spring animations in AppKit
appkit-spring-animation - - Use animator proxy for view animations
appkit-animator-proxy
- - 使用NSAnimationContext进行动画分组
appkit-nsanimation-context - - 使用Core Animation图层
appkit-core-animation - - 启用图层提升性能
appkit-layer-backed-views - - 利用图层隐式动画
appkit-implicit-animations - - 在AppKit中创建弹簧动画
appkit-spring-animation - - 使用animator代理实现视图动画
appkit-animator-proxy
Key Values Reference
关键参数参考
| Value | Usage |
|---|---|
| Standard iOS 17 spring animation |
| Classic spring configuration |
| Standard UI transition |
| Button press feedback |
| Minimum enter scale (never scale to 0) |
| Default micro-interaction duration |
| Maximum duration for UI animations |
| Sheet/drawer animation duration |
| 参数 | 用途 |
|---|---|
| 标准iOS 17弹簧动画 |
| 经典弹簧配置 |
| 标准UI转场动画 |
| 按钮按下反馈 |
| 最小进入缩放值(切勿缩放到0) |
| 默认微交互动画时长 |
| UI动画最大时长 |
| 弹窗/抽屉动画时长 |
Concept Mapping (Web to SwiftUI)
概念映射(Web → SwiftUI)
| Web Concept | SwiftUI Equivalent |
|---|---|
| |
| |
| Framer Motion spring | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Web概念 | SwiftUI对应实现 |
|---|---|
| |
| |
| Framer Motion spring | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
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 | 版本与参考信息 |