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

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

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

6条回答
  •  天命终不由人
    2021-01-30 13:16

    //For Swift 3: M_PI is depreciated now Use Double.pi

    let radians = atan2f(Float(yourView.transform.b), Float(yourView.transform.a));
    let degrees = radians * Float(180 / Double.pi)
    

    //For Swift 4:

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

提交回复
热议问题