A gesture that succeeds when the user performs a long press.


struct LongPressGesture


To recognize a long-press gesture on a view, create and configure the gesture, and then add it to the view using the gesture(_:including:) modifier. The following code snippet adds a long-press gesture to a Circle that animates the color of the circle from blue to red and then changes it to green when the gesture ends.

struct LongPressGestureView: View {
    @GestureState var isDetectingLongPress = false
    @State var completedLongPress = false
    var longPress: some Gesture {
        LongPressGesture(minimumDuration: 3)
            .updating($isDetectingLongPress) { currentstate, gestureState,
                    transaction in
                gestureState = currentstate
                transaction.animation = Animation.easeIn(duration: 2.0)
            .onEnded { finished in
                self.completedLongPress = finished
    var body: some View {
            .fill(self.isDetectingLongPress ?
                    (self.completedLongPress ? :
            .frame(width: 100, height: 100, alignment: .center)


Creating a Long-Press Gesture

init(minimumDuration: Double, maximumDistance: CGFloat)

Creates a long-press gesture with a minimum duration and a maximum distance that the interaction can move before the gesture fails.

var minimumDuration: Double

The minimum duration of the long press that must elapse before the gesture succeeds.

var maximumDistance: CGFloat

The maximum distance that the long press can move before the gesture fails.

typealias LongPressGesture.Body

A type that represents the long-press gesture and its behavior.

Performing the Gesture

func onChanged((Bool) -> Void) -> _ChangedGesture<LongPressGesture>

Adds an action to perform when the gesture’s value changes.

func onEnded((Bool) -> Void) -> _EndedGesture<LongPressGesture>

Adds an action to perform when the gesture ends.

typealias LongPressGesture.Value

The value of a long-press gesture.

Composing Gestures

func simultaneously<Other>(with: Other) -> SimultaneousGesture<LongPressGesture, Other>

Combines a gesture with another gesture to create a new gesture that recognizes both gestures at the same time.

func sequenced<Other>(before: Other) -> SequenceGesture<LongPressGesture, Other>

Sequences a gesture with another one to create a new gesture, which results in the second gesture only receiving events after the first gesture succeeds.

func exclusively<Other>(before: Other) -> ExclusiveGesture<LongPressGesture, Other>

Combines two gestures exclusively to create a new gesture where only one gesture succeeds, giving precedence to the first gesture.

Adding Modifier Keys to a Gesture

Transforming a Gesture

func map<T>((Bool) -> T) -> _MapGesture<LongPressGesture, T>

Returns a gesture that’s the result of mapping the given closure over the gesture.

See Also

Basic Gestures

Adding Interactivity with Gestures

Use gesture modifiers to add interactivity to your app.

struct TapGesture

A gesture that recognizes one or more taps.

struct DragGesture

A dragging motion that invokes an action as the drag-event sequence changes.

struct MagnificationGesture

A gesture that recognizes a magnification motion and tracks the amount of magnification.

struct RotationGesture

A gesture that recognizes a rotation motion and tracks the angle of the rotation.