Skip to content

Instantly share code, notes, and snippets.

@ershovio
Created November 23, 2019 17:22
Show Gist options
  • Save ershovio/6c0c392195ab55f7e703000df17c9d84 to your computer and use it in GitHub Desktop.
Save ershovio/6c0c392195ab55f7e703000df17c9d84 to your computer and use it in GitHub Desktop.
RotationGesture example
struct RotationGestureExample: View {
@State var rectangleRotationAngle: Angle = .zero
var body: some View {
// DragGesture creation
let rotationGesture = RotationGesture()
// Rotation angle recalculation for the rectangle
.onChanged { value in
self.rectangleRotationAngle = value
}
return Rectangle()
.foregroundColor(.green)
.cornerRadius(40)
// Rotate the rectangle
.rotationEffect(rectangleRotationAngle)
.frame(width: 200, height: 100, alignment: .center)
// Add the rotationGesture to this view
.gesture(rotationGesture)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment