TechnologiesSwiftUI

ManipulableModifier struct

iOSmacOStvOSwatchOSvisionOS✓ renders

How it works

ManipulableModifier is the modifier type that adds direct, gesture-driven manipulation to a view, letting people grab it and move or rotate it in place. You don't construct it directly; you apply it through the manipulable() modifier on any view that should respond to drag-to-move and drag-to-rotate interaction. Reach for it when a piece of your interface is meant to be handled rather than merely tapped — an object a person repositions, reorients, or inspects — and you want that behavior without wiring up your own gesture state, transform math, or coordinate bookkeeping.

  1. Apply manipulable() to make a view handlable

    Calling manipulable() on a view returns it wrapped in a ManipulableModifier, which installs the move-and-rotate interaction. In the example it sits at the end of the chain on the Image(systemName: "globe"), so the globe itself becomes the object a person can drag and turn.

  2. Order the modifier after appearance modifiers

    Because modifiers compose top-down, manipulable() should follow the styling that defines the view's visible shape and bounds. Here it comes after foregroundStyle(.blue), padding(), and background(.regularMaterial, in: .rect(cornerRadius: 16)), so the manipulation region matches the rounded material card the viewer actually sees and touches.

  3. Let the modifier own the transform

    ManipulableModifier tracks the accumulated translation and rotation internally and applies them to the wrapped view, so you don't declare @State for offset or angle or build a DragGesture. The Image in the example carries no gesture or transform state of its own — the modifier supplies all of it.

  4. Keep manipulable subjects distinct in the layout

    The modifier affects only the single view it's attached to, leaving its container untouched. The surrounding VStack, the Text("Globe") heading, and the Text("Drag to move and rotate") caption stay fixed in place; only the globe responds, which is why the caption can describe the gesture while the label above it holds still.

Try it — Move .manipulable() from the Image up to the whole VStack (place it after the trailing .padding()) and watch the entire stack — heading, globe, and caption together — become a single object you drag and rotate as a unit.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

ManipulableModifier.swift
struct ManipulableModifierDemo: View {
    var body: some View {
        VStack(spacing: 16) {
            Text("Globe")
                .font(.headline)
            Image(systemName: "globe")
                .font(.system(size: 64))
                .foregroundStyle(.blue)
                .padding()
                .background(.regularMaterial, in: .rect(cornerRadius: 16))
                .manipulable()
            Text("Drag to move and rotate")
                .font(.caption)
                .foregroundStyle(.secondary)
        }
        .padding()
    }
}
Live preview
Globe Drag to move and rotate
Globe Drag to move and rotate
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →