How it works
WorldScalingCompensation describes how SwiftUI reconciles a view's logical size with its physical size when content is presented in world space, such as inside a volume or an immersive scene. In flat windows a point maps to a fixed scale, but once content lives in the shared 3D space its on-screen size depends on distance and the dynamic scaling the system applies, so a view that looks correct up close can read as oversized or undersized as it moves away from the viewer. Use WorldScalingCompensation to declare whether a view should keep its intended physical dimensions regardless of that system scaling, or follow the surrounding world scale. Reach for it when precise real-world sizing matters — measurement overlays, controls anchored to physical objects, or text that must stay legible at a chosen physical size.
Read WorldScalingCompensation as a behavior value
WorldScalingCompensation is a small value type whose cases express the compensation policy you want the system to apply to a view's scale in world space. You don't construct it imperatively in the layout body; you select one of its values and hand it to SwiftUI, which then decides how the rendered size of content like the
Image(systemName: "globe")andText("World Scaling")relates to physical dimensions.Choose between compensated and automatic scaling
The type distinguishes content that should resist dynamic world scaling — preserving its specified physical size — from content that should scale with its surroundings. Picking the compensating behavior pins the
VStack(spacing: 12)so its glyph and labels hold a consistent real-world size as the viewer's distance changes, while the default behavior lets the same stack grow and shrink with the world.Apply it to the subtree, not the leaf
WorldScalingCompensation is supplied through SwiftUI's modifier and environment machinery so it cascades to a whole view subtree. Attaching it at the root of
WorldScalingCompensationDemo.bodymeans the choice governs every descendant — the.font(.headline)title and the.foregroundStyle(.secondary)caption alike — rather than forcing you to annotate each child individually.Let padding and intrinsic size define what gets compensated
Compensation acts on the resolved physical extent of the content, so the intrinsic sizing you express still matters. The
.font(.system(size: 44))symbol and the.padding()around the stack establish the dimensions WorldScalingCompensation then preserves or releases, which is why the policy reads most clearly on content that has a deliberate, measurable size.
WorldScalingCompensationDemo.body, then view the scene at increasing distance — the globe and labels will start tracking the world scale instead of holding their fixed physical size.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 WorldScalingCompensationDemo: View {
var body: some View {
VStack(spacing: 12) {
Image(systemName: "globe")
.font(.system(size: 44))
.foregroundStyle(.blue)
Text("World Scaling")
.font(.headline)
Text("Compensates content scale to the world space.")
.font(.caption)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
}
.padding()
}
}