How it works
HandActivationBehavior is a set of constants that describe how a hand gesture activates an interaction on platforms where the system tracks hand input, such as visionOS. SwiftUI uses it to decide whether a view responds to a direct touch, to a pinch driven by an indirect hand pointer, or to the system's default choice for the current context. Reach for it when a control should favor — or restrict itself to — a particular form of hand engagement instead of accepting whatever the platform supplies by default.
Choose an activation constant
HandActivationBehaviorexposes named constants rather than a free-form initializer, so you select one of its predefined values to express intent. The example uses.automatic, which lets the system pick the activation appropriate for the control and context.Apply it with handPointerBehavior(_:)
You don't construct the behavior in isolation; you hand it to a view modifier that governs hand-pointer activation. Here
handPointerBehavior(.automatic)attaches the behavior to aButton, telling SwiftUI how that button should treat an incoming hand gesture.Attach to an interactive view
The behavior is meaningful only on something the user can activate, so it sits on a control in the hierarchy. In the example it modifies the
Button("Pinch to Activate"), scoping the activation rule to that single button while the surroundingTextlabels are unaffected.Compose with the control's other modifiers
Because it's an ordinary view modifier, it stacks alongside the rest of the control's chain without conflict. The button keeps its
.borderedProminentbuttonStyleand simply gains the.automaticactivation rule on top of it.
.handPointerBehavior(.automatic) on the Button("Pinch to Activate") to a different HandActivationBehavior constant and observe how the button's response to a pinch versus a direct touch shifts.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 HandActivationBehaviorDemo: View {
var body: some View {
VStack(spacing: 16) {
Text("Hand Activation Behavior")
.font(.headline)
Button("Pinch to Activate") {}
.buttonStyle(.borderedProminent)
.handPointerBehavior(.automatic)
Text("Uses .automatic activation")
.font(.caption)
.foregroundStyle(.secondary)
}
.padding()
}
}