Skip to content

Gestures

Nick Sarno edited this page Jan 13, 2024 · 5 revisions

.withDragGesture

Add a DragGesture to a View.

RoundedRectangle(cornerRadius: 10)
     .frame(width: 300, height: 200)
     .withDragGesture()

Customize the gesture with optional parameters.

RoundedRectangle(cornerRadius: 10)
     .frame(width: 300, height: 200)
     .withDragGesture(
          [.vertical, .horizontal],
          resets: true,
          animation: .smooth,
          rotationMultiplier: 1.1,
          scaleMultiplier: 1.1,
          onChanged: { dragOffset in
               let tx = dragOffset.height
               let ty = dragOffset.width
          },
          onEnded: { dragOffset in
               let tx = dragOffset.height
               let ty = dragOffset.width
          }
     )

.withMagnificationGesture

Add a MagnificationGesture to a View.

RoundedRectangle(cornerRadius: 10)
     .frame(width: 300, height: 200)
     . withMagnificationGesture()

Customize the gesture with optional parameters.

RoundedRectangle(cornerRadius: 10)
     .frame(width: 300, height: 200)
     .withMagnificationGesture(resets: false, animation: .spring(), scaleMultiplier: 1.1) { scale in
                     
     }

.withRotationGesture

Add a RotationGesture to a View.

RoundedRectangle(cornerRadius: 10)
     .frame(width: 300, height: 200)
     . withRotationGesture()

Customize the gesture with optional parameters.

RoundedRectangle(cornerRadius: 10)
     .frame(width: 300, height: 200)
     .withRotationGesture(resets: false, animation: .spring()) { angle in
                    
     }
Clone this wiki locally