TechnologiesSwiftUIHover and Pointer Effects

HandActivationBehavior struct

iOSmacOStvOSwatchOSvisionOS✓ renders

An activation behavior specific to hand-driven input.

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.

  1. Choose an activation constant

    HandActivationBehavior exposes 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.

  2. 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 a Button, telling SwiftUI how that button should treat an incoming hand gesture.

  3. 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 surrounding Text labels are unaffected.

  4. 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 .borderedProminent buttonStyle and simply gains the .automatic activation rule on top of it.

Try it — Change .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.

HandActivationBehavior.swift
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()
    }
}
Live preview
Hand Activation Behavior Pinch to Activate Uses .automatic activation
Hand Activation Behavior Pinch to Activate Uses .automatic activation
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →