---
title: LongPressGesture
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/longpressgesture
---

# LongPressGesture

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

## Declaration

```swift
nonisolated struct LongPressGesture
```

## Mentioned in

Adding interactivity with gestures Composing SwiftUI gestures

## Overview

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:) modifier. Add a long-press gesture to a 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:)](swiftui/longpressgesture/init(minimumduration:).md)
- [init(minimumDuration:maximumDistance:)](swiftui/longpressgesture/init(minimumduration:maximumdistance:).md)
- [init(minimumDuration:maximumDistance:inputKinds:)](swiftui/longpressgesture/init(minimumduration:maximumdistance:inputkinds:).md)
- [minimumDuration](swiftui/longpressgesture/minimumduration.md)
- [maximumDistance](swiftui/longpressgesture/maximumdistance.md)

## Relationships

### Conforms To

- [Gesture](swiftui/gesture.md)

## See Also

### Recognizing long-press gestures

- [onLongPressGesture(minimumDuration:maximumDistance:perform:onPressingChanged:)](swiftui/view/onlongpressgesture(minimumduration:maximumdistance:perform:onpressingchanged:).md)
- [onLongPressGesture(minimumDuration:maximumDistance:inputKinds:perform:onPressingChanged:)](swiftui/view/onlongpressgesture(minimumduration:maximumdistance:inputkinds:perform:onpressingchanged:).md)
- [onLongPressGesture(minimumDuration:perform:onPressingChanged:)](swiftui/view/onlongpressgesture(minimumduration:perform:onpressingchanged:).md)
- [onLongTouchGesture(minimumDuration:perform:onTouchingChanged:)](swiftui/view/onlongtouchgesture(minimumduration:perform:ontouchingchanged:).md)
