spatial-swiftui-developer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpatial SwiftUI Developer
空间SwiftUI开发者
Description and Goals
说明与目标
This skill provides guidance for designing and implementing visionOS SwiftUI scenes that integrate RealityKit content. It helps you choose between SwiftUI and RealityKit APIs for 3D presentation and shows how to bridge between the two frameworks effectively.
本技能为设计和实现整合RealityKit内容的visionOS SwiftUI场景提供指导。它帮助你在3D展示场景中选择SwiftUI与RealityKit API,并展示如何有效桥接这两个框架。
Goals
目标
- Enable developers to build spatial UI experiences on visionOS
- Guide selection between SwiftUI and RealityKit APIs for 3D content
- Show how to integrate RealityKit content into SwiftUI scenes
- Demonstrate spatial interaction patterns with gestures
- Support proper windowing and immersion patterns
- 帮助开发者在visionOS上构建空间UI体验
- 指导在3D内容展示时选择SwiftUI与RealityKit API
- 展示如何将RealityKit内容整合到SwiftUI场景中
- 演示带手势的空间交互模式
- 支持正确的窗口管理与沉浸模式
What This Skill Should Do
本技能的适用场景
When building spatial UI with SwiftUI on visionOS, this skill should:
- Guide presentation surface selection - Help you choose between WindowGroup, volumetric windows, and ImmersiveSpace
- Select 3D APIs - Show when to use Model3D vs RealityView for different use cases
- Integrate RealityKit - Demonstrate how to load and embed RealityKit content in SwiftUI
- Handle spatial interaction - Provide patterns for spatial gestures and entity-targeted interactions
- Manage lifecycle - Ensure proper async loading and state management
Load the appropriate reference file from the tables below for detailed usage, code examples, and best practices.
在visionOS上使用SwiftUI构建空间UI时,本技能可用于:
- 指导展示载体选择 - 帮助你在WindowGroup、体积窗口和ImmersiveSpace之间做出选择
- 选择3D API - 展示不同场景下何时使用Model3D与RealityView
- 整合RealityKit - 演示如何在SwiftUI中加载和嵌入RealityKit内容
- 处理空间交互 - 提供空间手势和实体目标交互的实现模式
- 管理生命周期 - 确保异步加载和状态管理的正确性
可从下表中加载对应的参考文件,获取详细用法、代码示例和最佳实践。
Quick Start Workflow
快速入门流程
- Identify the presentation surface: , volumetric window, or
WindowGroup.ImmersiveSpace - Choose a 3D API: for simple models,
Model3Dfor full RealityKit scenes.RealityView - Load RealityKit content asynchronously and add entities in the make closure.
RealityView - Use RealityView attachments to place SwiftUI UI in 3D space when needed.
- Add spatial interaction with or entity-targeted gestures.
SpatialTapGesture - Update RealityKit content in the update closure, not in SwiftUI body.
RealityView - Validate scale using for volumes and
defaultSizefor immersive spaces.immersionStyle
- 确定展示载体:、体积窗口或
WindowGroup。ImmersiveSpace - 选择3D API:简单模型使用,完整RealityKit场景使用
Model3D。RealityView - 异步加载RealityKit内容,并在的make闭包中添加实体。
RealityView - 必要时,使用RealityView附件在3D空间中放置SwiftUI UI。
- 通过或实体目标手势添加空间交互。
SpatialTapGesture - 在的update闭包中更新RealityKit内容,而非SwiftUI body中。
RealityView - 为体积窗口设置、为沉浸空间设置
defaultSize以验证缩放比例。immersionStyle
Information About the Skill
关于本技能的详细信息
Core Concepts
核心概念
Scene and Spatial Presentation
场景与空间展示
- Use with
WindowGroupandwindowStyle(.volumetric)for volumes.defaultSize - Use for unbounded spatial scenes and
ImmersiveSpaceselection.immersionStyle - Use and
openImmersiveSpacefor transitions.dismissImmersiveSpace
- 对使用
WindowGroup和windowStyle(.volumetric)来创建体积窗口。defaultSize - 使用创建无边界空间场景,并选择
ImmersiveSpace。immersionStyle - 使用和
openImmersiveSpace实现场景切换。dismissImmersiveSpace
RealityKit Embedding in SwiftUI
在SwiftUI中嵌入RealityKit
- Use for full RealityKit scenes and per-frame updates.
RealityView - Use and RealityView attachments to embed SwiftUI views in 3D.
Attachment - Use and
ViewAttachmentEntityfor attachment entities.ViewAttachmentComponent
- 使用加载完整RealityKit场景并进行逐帧更新。
RealityView - 使用和RealityView附件在3D空间中嵌入SwiftUI视图。
Attachment - 使用和
ViewAttachmentEntity创建附件实体。ViewAttachmentComponent
3D Model Presentation
3D模型展示
- Use for async model loading with SwiftUI layout.
Model3D - Use and
Model3DPhasefor loading phases and animation choices.Model3DAsset
- 使用结合SwiftUI布局实现异步模型加载。
Model3D - 使用和
Model3DPhase处理加载阶段和动画选择。Model3DAsset
Spatial Input
空间输入
- Use for spatial tap locations in 2D/3D coordinate spaces.
SpatialTapGesture
- 使用处理2D/3D坐标系中的空间点击位置。
SpatialTapGesture
Reference Files
参考文件
| Reference | When to Use |
|---|---|
| When looking for feature-focused code patterns and general guidance. |
| When using Model3D for async model loading, assets, animation, and manipulation. |
| When setting up RealityView, attachments, and RealityKit integration patterns. |
| When implementing gestures and manipulation patterns for spatial input. |
| When managing windows and immersive space patterns. |
| When using SwiftUI spatial layout APIs and debug tools. |
| When implementing Chart3D and surface plot patterns. |
| 参考文件 | 使用场景 |
|---|---|
| 查找功能聚焦的代码模式和通用指导时使用。 |
| 使用Model3D进行异步模型加载、资源管理、动画和操作时使用。 |
| 设置RealityView、附件和RealityKit整合模式时使用。 |
| 实现空间输入的手势和操作模式时使用。 |
| 管理窗口和沉浸空间模式时使用。 |
| 使用SwiftUI空间布局API和调试工具时使用。 |
| 实现Chart3D和曲面图模式时使用。 |
Implementation Patterns
实现模式
- Use when you only need display and layout; use
Model3Dfor custom entity graphs and systems.RealityView - Keep RealityKit mutations inside make/update closures.
RealityView - Prefer attachments for UI that should remain SwiftUI-driven but positioned in 3D.
- Treat as a separate scene with its own lifecycle and environment actions.
ImmersiveSpace
- 仅需展示和布局时使用;需要自定义实体图和系统时使用
Model3D。RealityView - 将RealityKit的修改操作限制在的make/update闭包内。
RealityView - 对于需要保持SwiftUI驱动但要放置在3D空间中的UI,优先使用附件。
- 将视为独立场景,拥有自身的生命周期和环境操作。
ImmersiveSpace
Pitfalls and Checks
常见陷阱与检查项
- Do not block the main actor with synchronous model or entity loading.
- Do not update RealityKit entities inside SwiftUI body computation.
- Do not use volumetric window style with instead of
Window.WindowGroup - Do not omit for volumes; physical scale will be inconsistent.
defaultSize - Prefer for backgrounds instead of custom blur/material backgrounds.
.glassBackgroundEffect()
- 不要使用同步模型或实体加载阻塞主线程。
- 不要在SwiftUI body计算过程中更新RealityKit实体。
- 不要对而非
Window使用体积窗口样式。WindowGroup - 体积窗口不要省略,否则物理缩放比例会不一致。
defaultSize - 优先使用作为背景,而非自定义模糊/材质背景。
.glassBackgroundEffect()