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

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


You can do it this way...

CGFloat radians = atan2f(yourView.transform.b, yourView.transform.a); CGFloat degrees = radians * (180 / M_PI);


Swift:

// Note the type reference as Swift is now string Strictlet radians:Double = atan2( Double(yourView.transform.b), Double(yourView.transform.a))let degrees:CGFloat = radians * (CGFloat(180) / CGFloat(M_PI) )


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