TechnologiesSwiftUIHover and Pointer Effects

HandPointerBehavior struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A behavior that can be applied to the hand pointer while the user is

How it works

HandPointerBehavior is a set of constants that describe how the hand pointer should behave while a person interacts with a view in spatial contexts, such as visionOS. On platforms where a finger or hand drives the pointer, the system normally lifts the hand pointer away once a direct interaction begins; HandPointerBehavior lets you override that default and keep the pointer engaged—or defer to the platform's standard treatment. Reach for it when a control needs the hand pointer to stay present throughout a gesture, for example to reinforce ongoing contact with a button or interactive surface.

  1. Apply the behavior with handPointerBehavior(_:)

    You don't construct HandPointerBehavior directly into a view hierarchy; you pass one of its values to the handPointerBehavior(_:) view modifier, which establishes the preferred hand-pointer behavior for that subtree. In the example the modifier is attached to a Button so the preference applies to that control's interaction.

  2. Defer to the system with .automatic

    The .automatic constant tells SwiftUI to use the platform's default hand-pointer treatment, letting the system decide when the pointer engages or lifts during the interaction. The example uses .handPointerBehavior(.automatic), which is the right starting point when you want standard behavior and a place to opt into something more specific later.

  3. Scope the preference to an interactive view

    Because the modifier sets a preference, place it on the view whose interaction you mean to influence rather than on inert containers. Here it sits on the Button (styled with .buttonStyle(.borderedProminent)), so the hand-pointer behavior is tied to that tappable control while the surrounding VStack, Text, and Label are just where the button lives.

  4. Choose a non-default constant to change engagement

    HandPointerBehavior is an enumeration-like type whose other values let you keep the hand pointer present (rather than letting it lift) during a direct interaction. Swapping the value passed to .handPointerBehavior(.automatic) is how you move from system-default handling to an explicit, persistent pointer presence on that control.

Try it — Change .handPointerBehavior(.automatic) to a value that keeps the pointer engaged during the interaction, then interact with the Button to see the hand pointer stay present instead of lifting away.

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.

HandPointerBehavior.swift
struct HandPointerBehaviorDemo: View {
    var body: some View {
        VStack(spacing: 16) {
            Text("Hand Pointer Behavior")
                .font(.headline)
            Button {
                // action
            } label: {
                Label("Tap Me", systemImage: "hand.point.up.left")
                    .padding()
            }
            .buttonStyle(.borderedProminent)
            .handPointerBehavior(.automatic)
        }
        .padding()
    }
}
Live preview
Hand Pointer Behavior Tap Me
Hand Pointer Behavior Tap Me
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →