Get scale and rotation angle from CGAffineTransform?

hmdeep picture hmdeep · Jul 18, 2014 · Viewed 11.5k times · Source

i want to get scale factor and rotation angle form view.i'm already applied CGAffineTransform to that view.

Answer

Cornelius picture Cornelius · Jul 18, 2014

The current transformation of an UIView is stored in its transform property. This is a CGAffineTransform structure, you can read more about that here: https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html

You can get the angle in radians from the transform like this:

CGFloat angle = atan2f(yourView.transform.b, yourView.transform.a);

If you want the angle in degrees you need to convert it like this:

angle = angle * (180 / M_PI);

Get the scale like this:

CGFloat scaleX = view.transform.a;
CGFloat scaleY = view.transform.d;