SwiftUI 布局
Asked on 06/15/2025
1 search
SwiftUI's layout capabilities have been significantly enhanced, especially with the introduction of spatial layout features. At WWDC, Apple introduced new tools for building 3D experiences using SwiftUI, particularly on VisionOS. These tools allow developers to extend existing 2D layout concepts into 3D, enabling the creation of more immersive and interactive applications.
Key Features of SwiftUI Spatial Layout
-
3D Views: SwiftUI now supports 3D views, allowing developers to use familiar 2D layout tools to build 3D applications. This includes support for animations, resizing, and state management in a 3D context. Meet SwiftUI spatial layout
-
Depth Alignments: New depth-based variants of modifiers allow for volumetric layouts directly in SwiftUI. This includes depth alignments and layout-aware rotations, which help in creating rich 3D layouts. Meet SwiftUI spatial layout
-
Rotation Layout: The rotation 3D layout modifier supports rotations on any angle and axis, enabling dynamic and visually appealing arrangements. Meet SwiftUI spatial layout
-
Spatial Containers: These allow for overlapping content in the same 3D space, providing more flexibility in how content is displayed and interacted with. Meet SwiftUI spatial layout
These enhancements make SwiftUI a powerful tool for creating 3D applications, especially when combined with RealityKit for more complex behaviors. If you're interested in learning more about these features, I recommend watching the session "Meet SwiftUI spatial layout" from WWDC 2025.

Meet SwiftUI spatial layout
Explore new tools for building spatial experiences using SwiftUI. Learn the basics of 3D SwiftUI views on visionOS, customize existing layouts with depth alignments, and use modifiers to rotate and position views in space. Discover how to use spatial containers to align views in the same 3D space, helping you create immersive and engaging apps.

SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.

What’s new in visionOS 26
Explore exciting new features in visionOS 26. Discover enhanced volumetric APIs and learn how you can combine the power of SwiftUI, RealityKit and ARKit. Find out how you can build more engaging apps and games using faster hand tracking and input from spatial accessories. Get a sneak peek at updates to SharePlay, Compositor Services, immersive media, spatial web, Enterprise APIs, and much more.