One Logo Pool Ball
SwiftUI · IOS API REFERENCE

LongPressGesture

struct · iOS 13.0+ · SDK 27.1

nonisolated struct LongPressGesture

A gesture that succeeds when the user performs a long press. To recognize a long-press gesture on a view, create and configure the gesture, then add it to the view using the ``View/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) } }

Members (6)

get · iOS 13.0+

maximumDistance

TypeScript
get maximumDistance(): number
Swift declaration
nonisolated var maximumDistance: CGFloat { get set }

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

set · iOS 13.0+

maximumDistance

TypeScript
set maximumDistance(value: number)
Swift declaration
nonisolated var maximumDistance: CGFloat { get set }

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

init · iOS 27.0+

init

TypeScript
static initMinimumDurationMaximumDistanceInputKinds(minimumDuration?: number, maximumDistance?: number, inputKinds?: _SwiftUICore_GestureInputKinds): LongPressGesture
Swift declaration
nonisolated init(minimumDuration: Double = 0.5, maximumDistance: CGFloat = 10, inputKinds: GestureInputKinds = .all)

Creates a long-press gesture with a minimum duration, a maximum distance, and the input kinds the gesture recognizes. - Parameters: - minimumDuration: The minimum duration of the long press that must elapse before the gesture succeeds. - maximumDistance: The maximum distance that the fingers or cursor performing the long press can move before the gesture fails. - inputKinds: A set of input kinds that this gesture recognizes. If not specified, the gesture will recognize all applicable input kinds that a person can use to perform it.

init · iOS 13.0+

init

TypeScript
static initMinimumDurationMaximumDistance(minimumDuration?: number, maximumDistance?: number): LongPressGesture
Swift declaration
nonisolated init(minimumDuration: Double = 0.5, maximumDistance: CGFloat = 10)

Creates a long-press gesture with a minimum duration and a maximum distance that the interaction can move before the gesture fails. - Parameters: - minimumDuration: The minimum duration of the long press that must elapse before the gesture succeeds. - maximumDistance: The maximum distance that the fingers or cursor performing the long press can move before the gesture fails.

get · iOS 13.0+

minimumDuration

TypeScript
get minimumDuration(): number
Swift declaration
var minimumDuration: Double

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

set · iOS 13.0+

minimumDuration

TypeScript
set minimumDuration(value: number)
Swift declaration
var minimumDuration: Double

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

Skipped declarations

No declarations were skipped in this snapshot.

All SwiftUI types →