I would like an analog clock, I could set the hands (rectangle) of the clock manually, using DragGesture control. But if I want to set the hand backwards immediately after clicking, it turns 180 degrees. If I want to move it forward, it works fine, but not backwards.
What could be the problem?
struct ContentView: View {
@State private var angle: Double = 0
var body: some View {
Rectangle()
.fill(Color.blue)
.frame(width: 10, height: 100)
.rotationEffect(Angle(degrees: angle), anchor: .bottom)
.gesture(
DragGesture()
.onChanged { value in
let vector = CGVector(dx: value.translation.width, dy: value.translation.height)
let radians = atan2(vector.dy, vector.dx)
let newAngle = radians * 180 / .pi
self.angle = Double(newAngle)
}
)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
5
0
772