View ModifieriOS 18.0+macOS 15.0+tvOS 18.0+watchOS 11.0+handGestureShortcut(_:isEnabled:) in SwiftUI
Declaration
compose().handGestureShortcut(
shortcut: SwiftUI.HandGestureShortcut,
options?: {
isEnabled?: boolean;
}
)nonisolated func handGestureShortcut(
_ shortcut: HandGestureShortcut,
isEnabled: Bool = true
) -> some ViewParameters
shortcut*SwiftUI.HandGestureShortcutThe shortcut to associate with this control.
options.isEnabledbooleanA Boolean value that indicates whether the shortcut is is enabled for this control.
Discussion
Performing the control's shortcut while the control is anywhere in the frontmost scene is equivalent to direct interaction with the control to perform its primary action.
The following example lets users of a watchOS music app toggle playback by double-tapping their thumb and index finger together:
struct PlaybackControls: View {
let model: TrackModel
var body: some View {
HStack {
Button("Skip Back") {
model.skipBack()
}
Button("Play/Pause") {
model.playPause()
}
.handGestureShortcut(.primaryAction)
Button("Skip Forward") {
model.skipForward()
}
}
}
}The target of a hand gesture shortcut is resolved in a leading-to-trailing traversal of the active scene.
See also
More in Gestures and input.
- defaultHoverEffectSets the default hover effect to use for views within this view.
- defersSystemGesturesSets the screen edge from which you want your gesture to take precedence over the system gesture.
- dragConfigurationConfigures a drag session.
- dragContainerA container with draggable views. The drag payload is identifiable. To form the payload, use the identifier of the dragged view inside the container.
- dragContainerSelectionProvides multiple item selection support for drag containers.
- gestureAttaches a gesture to the view with a lower precedence than gestures defined by the view.
- highPriorityGestureAttaches a gesture to the view with a higher precedence than gestures defined by the view.
- hoverEffectApplies a hover effect to this view.
- hoverEffectDisabledAdds a condition that controls whether this view can display hover effects.
- presentationDragIndicatorSets the visibility of the drag indicator on top of a sheet.
- simultaneousGestureAttaches a gesture to the view to process simultaneously with gestures defined by the view.