iphone sdk CGAffineTransform getting the angle of rotation of an object

前端 未结 5 1290
清酒与你
清酒与你 2020-11-27 04:19

how do i calculate the angle of rotation for any given object (ie a uiimageview)?

5条回答
  •  余生分开走
    2020-11-27 04:45

    Technically you can't, because the transform can include a skew operation which turns the image into a parallelogram and the rotation angle isn't defined anymore.

    Anyway, since the rotation matrix generates

     cos(x)  sin(x)   0
    -sin(x)  cos(x)   0
       0        0     1
    

    You can recover the angle with

    return atan2(transform.b, transform.a);
    

提交回复
热议问题