Get the current angle/rotation/radian for a UIView?

前端 未结 6 1304
傲寒
傲寒 2021-01-30 12:40

How do you get the current angle/rotation/radian a UIView has?

6条回答
  •  无人及你
    2021-01-30 13:17

    A lot of the other answers reference atan2f, but given that we're operating on CGFloats, we can just use atan2 and skip the unnecessary intermediate cast:

    Swift 4:

    let radians = atan2(yourView.transform.b, yourView.transform.a)
    let degrees = radians * 180 / .pi
    

提交回复
热议问题