I studied the rotation setting of transform, and after adjusting it for a long time, I thought that the rotation was wrongly written, and found that two different view objects were wrongly written. Anyway, let’s record the rotation-related operations.
The arguments are all in radians.
Take a picture as an example.
let img = UIImageView.init()
img.image = UIImage(named: "demo")
- initial value
img.transform = CGAffineTransformIdentity
img.transform = CGAffineTransform(rotationAngle: 0)
- Rotate to the specified angle 90 degrees
img.transform = CGAffineTransform(rotationAngle: Double.pi)
- Rotate 90 degrees
img.transform = CGAffineTransformRotate(img.transform, Double.pi)
- Get the rotation radian
let transform = img.transform
let angle = atan2(transform.b,transform.a)
// 弧度转角度
let degree = angle * 180 / Double.pi