<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/LongPressGesture",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI16LongPressGestureV"
  },
  "title" : "LongPressGesture"
}
-->

# LongPressGesture

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

```
nonisolated struct LongPressGesture
```

## Overview

To recognize a long-press gesture on a view, create and configure the
gesture, then add it to the view using the [`gesture(_:including:)`](/documentation/SwiftUI/View/gesture(_:including:))
modifier.

Add a long-press gesture to a [`Circle`](/documentation/SwiftUI/Circle) to animate its color from blue to
red, and then change it to green when the gesture ends:

```
struct LongPressGestureView: View {
    @GestureState private var isDetectingLongPress = false
    @State private 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 {
        Circle()
            .fill(self.isDetectingLongPress ?
                Color.red :
                (self.completedLongPress ? Color.green : Color.blue))
            .frame(width: 100, height: 100, alignment: .center)
            .gesture(longPress)
    }
}
```

## Topics

### Creating a long press gesture

[`init(minimumDuration:)`](/documentation/SwiftUI/LongPressGesture/init(minimumDuration:))

Creates a long-press gesture with a minimum duration

[`init(minimumDuration:maximumDistance:)`](/documentation/SwiftUI/LongPressGesture/init(minimumDuration:maximumDistance:))

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

[`init(minimumDuration:maximumDistance:inputKinds:)`](/documentation/SwiftUI/LongPressGesture/init(minimumDuration:maximumDistance:inputKinds:))

Creates a long-press gesture with a minimum duration, a maximum
distance, and the input kinds the gesture recognizes.

[`minimumDuration`](/documentation/SwiftUI/LongPressGesture/minimumDuration)

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

[`maximumDistance`](/documentation/SwiftUI/LongPressGesture/maximumDistance)

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



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)