TechnologiesSwiftUIImmersive Spaces and visionOS

ProgressiveImmersionAspectRatio struct

iOSmacOStvOSwatchOSvisionOS✓ renders

Constants that specify the aspect ratio of a progressive immersive space.

How it works

ProgressiveImmersionAspectRatio is a set of named constants that describe the shape of the portal through which a progressive immersive space presents your content on visionOS. In progressive immersion, your scene occupies a bounded region of the wearer's view rather than the full surround, and this type lets you declare whether that region reads as a wide landscape opening or a tall portrait one. Reach for it when you configure an ImmersiveSpace with the progressive immersion style and want to control the proportions of the immersive viewport. Because it is a simple value type, you can store a selected aspect ratio in state and drive it from ordinary controls.

  1. Hold a value with the ProgressiveImmersionAspectRatio type

    The type is the unit you pass when configuring a progressive immersive space, so the first move is to keep one around. Here the current choice lives in @State private var aspect: ProgressiveImmersionAspectRatio, giving the view a single source of truth that other code can read and write.

  2. Choose between the .landscape and .portrait constants

    ProgressiveImmersionAspectRatio exposes its options as static members, where .landscape requests a wide opening and .portrait a tall one. The state is seeded with .landscape, and each option surfaces explicitly through ProgressiveImmersionAspectRatio.landscape and ProgressiveImmersionAspectRatio.portrait.

  3. Tag selectable options so the picker yields the right value

    Because the constants are concrete, equatable values, you can bind them directly to a selection control. Each Text row carries a .tag(...) whose payload is one of the constants, so the picker hands back a fully-typed ProgressiveImmersionAspectRatio instead of an index or string.

  4. Bind the stored aspect ratio to a control

    A two-way binding lets the user pick the proportion at runtime. The Picker writes through selection: $aspect, so toggling between Landscape and Portrait mutates the same ProgressiveImmersionAspectRatio value you would later feed to a progressive ImmersiveSpace.

Try it — Change @State private var aspect: ProgressiveImmersionAspectRatio = .landscape to = .portrait and watch the segmented picker open on the tall option instead of the wide one.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

ProgressiveImmersionAspectRatio.swift
struct ProgressiveImmersionAspectRatioDemo: View {
    @State private var aspect: ProgressiveImmersionAspectRatio = .landscape

    var body: some View {
        VStack(spacing: 16) {
            Text("Progressive Immersion")
                .font(.headline)
            Picker("Aspect Ratio", selection: $aspect) {
                Text("Landscape").tag(ProgressiveImmersionAspectRatio.landscape)
                Text("Portrait").tag(ProgressiveImmersionAspectRatio.portrait)
            }
            .pickerStyle(.segmented)
        }
        .padding()
    }
}
Live preview
Progressive Immersion Landscape Portrait
Progressive Immersion Landscape Portrait
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →