How to show or hide the system hand menu in immersive spaces

We can hide the system hand menu in Immersive Spaces using the persistentSystemOverlays modifier.

.persistentSystemOverlays(.automatic) // default
.persistentSystemOverlays(.hidden)
.persistentSystemOverlays(.visible) 

In this example we can use a hand-anchored menu to switch between hidden and visible.

struct Example016: View {

    @State var vis: Visibility = .automatic

    @State var handTrackedEntity: Entity = {
        let handAnchor = AnchorEntity(.hand(.left, location: .aboveHand))
        return handAnchor
    }()

    var body: some View {
        RealityView { content, attachments in

            if let scene = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
                content.add(scene)
            }

            content.add(handTrackedEntity)

            if let attachmentEntity = attachments.entity(for: "AttachmentContent") {
                attachmentEntity.components[BillboardComponent.self] = .init()

                handTrackedEntity.addChild(attachmentEntity)

            }

        } update: { content, attachments in

        } attachments: {
            Attachment(id: "AttachmentContent") {
                HStack(spacing: 12) {
                    Button(action: {
                        vis = .hidden
                    }, label: {
                        Image(systemName: vis == .hidden ? "eye.slash.fill" : "eye.slash")
                    })

                    Button(action: {
                        vis = .visible
                    }, label: {
                        Image(systemName: vis == .visible ? "eye.fill" : "eye")
                    })
                }
            }
        }
        .persistentSystemOverlays(vis)
    }
}

This modifier can be useful when we need to create our own hand gestures or menus.

Note: even with this set to .hidden, visionOS will still show this overlay if the user performs the gesture, then a pinch gesture.

Video demo showing persistentSystemOverlays affecting the hand anchors system menu.

Support our work so we can continue to bring you new examples and articles.

Questions or feedback?