Structure

MagnificationGesture

A gesture that recognizes a magnification motion and tracks the amount of magnification.

Declaration

struct MagnificationGesture

Overview

A magnification gesture tracks how a magnification event sequence changes. To recognize a magnification gesture on a view, create and configure the gesture, and then add it to the view using the gesture(_:including:) modifier. The following code snippet adds a magnification gesture to a Circle and changes the size of the circle while the user performs the gesture, and resets it to its original size when the gesture finishes.

struct MagnificationGestureView: View {
    
    @GestureState var magnifyBy = CGFloat(1.0)
    
    var magnification: some Gesture {
        MagnificationGesture()
            .updating($magnifyBy) { currentState, gestureState, transaction in
                gestureState = currentState
            }
    }
    
    var body: some View {
        Circle()
            .frame(width: 100 * magnifyBy,
                   height: 100 * magnifyBy,
                   alignment: .center)
            .gesture(magnification)
    }
}

Topics

Creating a Magnification Gesture

init(minimumScaleDelta: CGFloat)

Creates a magnification gesture with a given minimum delta for the gesture to start.

var minimumScaleDelta: CGFloat

The minimum required delta before the gesture starts.

typealias MagnificationGesture.Body

A type that represents the magnification gesture and its behavior.

Performing the Gesture

func onChanged((CGFloat) -> Void) -> _ChangedGesture<MagnificationGesture>

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

func onEnded((CGFloat) -> Void) -> _EndedGesture<MagnificationGesture>

Adds an action to perform when the gesture ends.

typealias MagnificationGesture.Value

The floating point value representing the amount of magnification for the magnification gesture.

Composing Gestures

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

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