RotateGesture
A gesture that recognizes a rotation motion and tracks the angle of the rotation.
Declaration
struct RotateGestureOverview
A rotate gesture tracks how a rotation event sequence changes. To recognize a rotate gesture on a view, create and configure the gesture, and then add it to the view using the gesture(_:including:) modifier.
Add a rotate gesture to a Rectangle and apply a rotation effect:
struct RotateGestureView: View {
@State private var angle = Angle(degrees: 0.0)
var rotation: some Gesture {
RotateGesture()
.onChanged { value in
angle = value.rotation
}
}
var body: some View {
Rectangle()
.frame(width: 200, height: 200, alignment: .center)
.rotationEffect(angle)
.gesture(rotation)
}
}