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.
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.Choose between the .landscape and .portrait constants
ProgressiveImmersionAspectRatioexposes its options as static members, where.landscaperequests a wide opening and.portraita tall one. The state is seeded with.landscape, and each option surfaces explicitly throughProgressiveImmersionAspectRatio.landscapeandProgressiveImmersionAspectRatio.portrait.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
Textrow carries a.tag(...)whose payload is one of the constants, so the picker hands back a fully-typedProgressiveImmersionAspectRatioinstead of an index or string.Bind the stored aspect ratio to a control
A two-way binding lets the user pick the proportion at runtime. The
Pickerwrites throughselection: $aspect, so toggling between Landscape and Portrait mutates the sameProgressiveImmersionAspectRatiovalue you would later feed to a progressiveImmersiveSpace.
@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.
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()
}
}