Contents

MagnifyGesture

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

Declaration

struct MagnifyGesture

Overview

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

Add a magnify gesture to a Circle that changes its size while the user performs the gesture:

struct MagnifyGestureView: View {
    @GestureState private var magnifyBy = 1.0

    var magnification: some Gesture {
        MagnifyGesture()
            .updating($magnifyBy) { value, gestureState, transaction in
                gestureState = value.magnification
            }
    }

    var body: some View {
        Circle()
            .frame(width: 100, height: 100)
            .scaleEffect(magnifyBy)
            .gesture(magnification)
    }
}

Topics

Creating the gesture

See Also

Recognizing gestures that change over time