Gestures
Define interactions from taps, clicks, and swipes to fine-grained gestures.
Overview
Respond to gestures by adding gesture modifiers to your views. You can listen for taps, drags, pinches, and other standard gestures.
[Image]
You can also compose custom gestures from individual gestures using the simultaneously(with:), sequenced(before:), or exclusively(before:) modifiers, or combine gestures with keyboard modifiers using the modifiers(_:) modifier.
For design guidance, see Gestures in the Human Interface Guidelines.
Topics
Essentials
Recognizing tap gestures
Recognizing long press gestures
onLongPressGesture(minimumDuration:maximumDistance:perform:onPressingChanged:)onLongPressGesture(minimumDuration:perform:onPressingChanged:)onLongTouchGesture(minimumDuration:perform:onTouchingChanged:)LongPressGesture
Recognizing spatial events
Recognizing gestures that change over time
gesture(_:)gesture(_:isEnabled:)gesture(_:name:isEnabled:)gesture(_:including:)DragGestureWindowDragGestureMagnifyGestureRotateGestureRotateGesture3DGestureMask
Recognizing Apple Pencil gestures
onPencilDoubleTap(perform:)onPencilSqueeze(perform:)preferredPencilDoubleTapActionpreferredPencilSqueezeActionPencilPreferredActionPencilDoubleTapGestureValuePencilSqueezeGestureValuePencilSqueezeGesturePhasePencilHoverPose
Combining gestures
Composing SwiftUI gesturessimultaneousGesture(_:including:)simultaneousGesture(_:isEnabled:)simultaneousGesture(_:name:isEnabled:)SequenceGestureSimultaneousGestureExclusiveGesture
Defining custom gestures
highPriorityGesture(_:including:)highPriorityGesture(_:isEnabled:)highPriorityGesture(_:name:isEnabled:)handGestureShortcut(_:isEnabled:)defersSystemGestures(on:)GestureAnyGestureHandActivationBehaviorHandGestureShortcut