iOS transform rotateSummary

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")
  1. initial value
    insert image description here
img.transform = CGAffineTransformIdentity
img.transform = CGAffineTransform(rotationAngle: 0)
  1. Rotate to the specified angle 90 degrees

insert image description here

img.transform = CGAffineTransform(rotationAngle: Double.pi)
  1. Rotate 90 degrees
    insert image description here
img.transform = CGAffineTransformRotate(img.transform, Double.pi)
  1. Get the rotation radian
let transform = img.transform
let angle = atan2(transform.b,transform.a)
// 弧度转角度
let degree = angle * 180 / Double.pi 

Guess you like

Origin blog.csdn.net/xo19882011/article/details/131914032
ios