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.
Apply the behavior with handPointerBehavior(_:)
You don't construct
HandPointerBehaviordirectly into a view hierarchy; you pass one of its values to thehandPointerBehavior(_:)view modifier, which establishes the preferred hand-pointer behavior for that subtree. In the example the modifier is attached to aButtonso the preference applies to that control's interaction.Defer to the system with .automatic
The
.automaticconstant 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.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 surroundingVStack,Text, andLabelare just where the button lives.Choose a non-default constant to change engagement
HandPointerBehavioris 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.
.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.
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()
}
}