TechnologiesSwiftUIOrnaments and Glass Effects

OrnamentAttachmentAnchor struct

iOSmacOStvOSwatchOSvisionOS✓ renders

An attachment anchor for an ornament.

How it works

OrnamentAttachmentAnchor describes where an ornament docks relative to a scene's content. In visionOS, an ornament is an auxiliary control surface — toolbars, playback controls, tab bars — that floats outside a window's bounds without crowding the primary content, and the anchor is what tells SwiftUI which edge or position that floating element should hug. Rather than measuring offsets by hand, you hand the framework a semantic location and it keeps the ornament correctly placed as the scene resizes or repositions. Reach for OrnamentAttachmentAnchor whenever you call the ornament(attachmentAnchor:contentAlignment:ornament:) modifier and need to say where the accessory belongs.

  1. Pass an anchor to ornament(attachmentAnchor:ornament:)

    The ornament modifier takes an OrnamentAttachmentAnchor as its attachmentAnchor argument and a view builder that produces the floating accessory. In the example, .ornament(attachmentAnchor: .scene(.bottom)) attaches the trailing closure's controls to the host view, which here is a Text("Main Content") card.

  2. Choose a scene-relative position with .scene(_:)

    The type vends ornaments through the static .scene(_:) factory, which positions the ornament relative to the scene's bounds. The example uses .scene(.bottom), docking the accessory along the lower edge of the content; passing .top, .leading, or .trailing instead moves it to the corresponding side.

  3. Supply a UnitPoint to place the ornament

    .scene(_:) accepts a UnitPoint, so the anchor isn't limited to named edges — any normalized point such as .topLeading, .center, or .bottomTrailing works, letting you pin the accessory to a precise spot. The example's .bottom is one of these standard UnitPoint values.

  4. Build the ornament content in the trailing closure

    Whatever you return from the ornament's view builder rides along at the anchored location. Here the closure provides an HStack of Image(systemName:) playback glyphs — play.fill, pause.fill, and stop.fill — which become the floating control strip the anchor positions.

  5. Finish the floating surface with glassBackgroundEffect()

    Because the ornament sits outside the window's material, give its content its own backing so it reads as a distinct floating panel. The example applies .glassBackgroundEffect() to the padded HStack, producing the translucent capsule that the bottom anchor parks beneath the content card.

Try it — Change .scene(.bottom) to .scene(.top) and watch the glass playback strip jump to the upper edge of the content card.

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.

OrnamentAttachmentAnchor.swift
struct OrnamentAttachmentAnchorDemo: View {
    var body: some View {
        Text("Main Content")
            .font(.title)
            .padding(40)
            .background(.regularMaterial, in: .rect(cornerRadius: 16))
            .ornament(attachmentAnchor: .scene(.bottom)) {
                HStack {
                    Image(systemName: "play.fill")
                    Image(systemName: "pause.fill")
                    Image(systemName: "stop.fill")
                }
                .padding()
                .glassBackgroundEffect()
            }
            .padding()
    }
}
Live preview
Main Content
Main Content
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →