MagnifyGesture

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

StructureiOS 17.0+macOS 14.0+MagnifyGesture in SwiftUI

Declaration

React
type MagnifyGesture = { minimumScaleDelta?: number; } | { minimumScaleDelta?: number; inputKinds?: GestureInputKinds; };
Swift
nonisolated struct MagnifyGesture

Type methods

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 View.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)
    }
}

From Apple’s SwiftUI documentation. Code samples there are Swift.

See also

More in Gestures and input.