How do you get the current angle/rotation/radian a UIView has?
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 Strict
let 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 CGFloat
s, we can just use atan2
and skip the unnecessary intermediate cast:
let radians = atan2(yourView.transform.b, yourView.transform.a)
let degrees = radians * 180 / .pi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With