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


struct DragGesture


To recognize a drag gesture on a view, create and configure the gesture, and then add it to the view using the gesture(_:including:) modifier.

Add a drag gesture to a Circle and change its color while the user performs the drag gesture:

struct DragGestureView: View {
    @State var isDragging = false
    var drag: some Gesture {
            .onChanged { _ in self.isDragging = true }
            .onEnded { _ in self.isDragging = false }
    var body: some View {
            .fill(self.isDragging ? :
            .frame(width: 100, height: 100, alignment: .center)


Creating a Drag Gesture

init(minimumDistance: CGFloat, coordinateSpace: CoordinateSpace)

Creates a dragging gesture with the minimum dragging distance before the gesture succeeds and the coordinate space of the gesture’s location.

var minimumDistance: CGFloat

The minimum dragging distance before the gesture succeeds.

var coordinateSpace: CoordinateSpace

The coordinate space of the dragging gesture’s location.

typealias DragGesture.Body

A type that represents the drag gesture and its behavior.

Performing the Gesture

func onChanged((Value) -> Void) -> _ChangedGesture<DragGesture>

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

func onEnded((Value) -> Void) -> _EndedGesture<DragGesture>

Adds an action to perform when the gesture ends.

struct DragGesture.Value

The attributes of a drag gesture.

Composing Gestures

func simultaneously<Other>(with: Other) -> SimultaneousGesture<DragGesture, 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<DragGesture, 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<DragGesture, 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

func modifiers(EventModifiers) -> _ModifiersGesture<DragGesture>

Combines a gesture with keyboard modifiers.

Transforming a Gesture

func map<T>((Value) -> T) -> _MapGesture<DragGesture, T>

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


Conforms To

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 LongPressGesture

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

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.