Structure

RotationGesture

A gesture that recognizes a rotation motion and tracks the angle of the rotation.

Declaration

struct RotationGesture

Overview

A rotation gesture tracks how a rotation event sequence changes. To recognize a rotation gesture on a view, create and configure the gesture, and then add it to the view using the gesture(_:including:) modifier.

Add a rotation gesture to a Rectangle and apply a rotation effect:

struct RotationGestureView: View {
    @State var angle = Angle(degrees: 0.0)
    
    var rotation: some Gesture {
        RotationGesture()
            .onChanged { angle in
                self.angle = angle
            }
    }
    
    var body: some View {
        Rectangle()
            .frame(width: 200, height: 200, alignment: .center)
            .rotationEffect(self.angle)
            .gesture(rotation)
    }
}

Topics

Creating a Rotation Gesture

init(minimumAngleDelta: Angle)

Creates a rotation gesture with a minimum delta for the gesture to start.

var minimumAngleDelta: Angle

The minimum delta required before the gesture succeeds.

typealias RotationGesture.Body

A type that represents the rotation gesture and its behavior.

Performing the Gesture

func onChanged((Angle) -> Void) -> _ChangedGesture<RotationGesture>

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

func onEnded((Angle) -> Void) -> _EndedGesture<RotationGesture>

Adds an action to perform when the gesture ends.

typealias RotationGesture.Value

The angle of the rotation gesture.

Composing Gestures

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

Transforming a Gesture

func map<T>((Angle) -> T) -> _MapGesture<RotationGesture, T>

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

Relationships

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