Gestures

Define interactions from taps, clicks, and swipes to fine-grained gestures.

Overview

Respond to taps and gestures by adding gesture modifiers to your views. Create custom gestures from individual gestures using the simultaneously(with:), sequenced(before:), or exclusively(before:) modifiers, or combine gestures with keyboard modifiers using the modifiers(_:) modifier.

Topics

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 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.

Combined Gestures

Composing SwiftUI Gestures

Combine gestures to create complex interactions.

struct SequenceGesture

A gesture that’s a sequence of two gestures.

struct SimultaneousGesture

A gesture containing two gestures that can happen at the same time with neither of them preceeding the other.

struct ExclusiveGesture

A gesture that consists of two gestures where only one of them can succeed.

Custom Gestures

protocol Gesture

An instance that matches a sequence of events to a gesture, and returns a stream of values for each of its states.

struct AnyGesture

A type-erased gesture.

Dynamic View Properties

struct GestureState

A property wrapper type that updates a property while the user performs a gesture and resets the property back to its initial state when the gesture ends.

struct GestureStateGesture

A gesture that updates the state provided by a gesture’s updating callback.

Gesture Support

struct GestureMask

Options that control how adding a gesture to a view affect’s other gestures recognized by the view and its subvies.

See Also

Data and Events

State and Data Flow

Control and respond to the flow of data and changes within your app’s models.