I am using UIRotationGestureRecognizer to rotate an image. I would like to convert the angle of rotation from Radians to Degrees becuase I can think better in degrees. I found a solution on stack and other sources but for some reason the solution does not seem to work
For example, when I rotate the image counter clockwise about 45 degrees am getting a degree value of approximately -0.15 from the formula???
@objc func handleImageRotation(sender:
UIRotationGestureRecognizer){
guard sender.view != nil else{return}
if sender.state == .began || sender.state == .changed {
// rotation enacted
imageView.transform = imageView.transform.rotated(by: sender.rotation)
rotationAngleRads = sender.rotation
rotationAngleDegs = rad2Deg(radians: rotationAngleRads)
print("Degrees: \(rotationAngleDegs!)")
sender.rotation = 0
}
}
// Convert Radians to Degress
private func rad2Deg(radians: CGFloat) -> Double{
let angle = Double(radians) * (180 / .pi)
return Double(angle)
}