highPriorityGesture
Attaches a gesture to the view with a higher precedence than gestures defined by the view.
Overloads
3 ways to call compose().highPriorityGesture(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().highPriorityGesture(
gesture: SwiftUI.Gesture,
options?: {
including?: SwiftUI.GestureMask;
}
)nonisolated func highPriorityGesture<T>(
_ gesture: T,
including mask: GestureMask = .all
) -> some View
where T : GestureParameters
gesture*SwiftUI.GestureA gesture to attach to the view.
options.includingSwiftUI.GestureMask
Discussion
Use this method when you need to define a high priority gesture
to take precedence over the view's existing gestures. The
example below defines a custom gesture that prints a message to the
console and attaches it to the view's VStack. Inside the VStack
a red heart Image defines its own TapGesture handler that
also prints a message to the console, and a blue rectangle
with no custom gesture handlers. Tapping or clicking any of the
views results in a console message from the high priority gesture
attached to the enclosing VStack.
struct HighPriorityGestureExample: View {
@State private var message = "Message"
let newGesture = TapGesture().onEnded {
print("Tap on VStack.")
}
var body: some View {
VStack(spacing:25) {
Image(systemName: "heart.fill")
.resizable()
.frame(width: 75, height: 75)
.padding()
.foregroundColor(.red)
.onTapGesture {
print("Tap on image.")
}
Rectangle()
.fill(Color.blue)
}
.highPriorityGesture(newGesture)
.frame(width: 200, height: 200)
.border(Color.purple)
}
}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.
- handGestureShortcutAssigns a hand gesture shortcut to the modified control.
- 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.