I have some a UIView with several user created subviews. The user can move and rotate the subviews. I’m using the transform attribute of UIView to accomplish this. I want to save the “document” in order to recreate it later.
I’m currently writing out the transform attribute out to a file along with some other data. But the transform attribute is 6 number set, instead I would like to somehow get the degrees of rotation that the user made and save that.
Is there any way to take a transform and get back out the total rotation that created the transform? Obviously as the user was moving the object around the screen, many little transforms were done.
There is an easier way than even the math that lucius points to. You can use a helper keypath that Core Animation provides to extract the current rotation of a UIView’s backing layer:
This will give you the current rotation of the view, in radians. Note that this reports positive values for the first clockwise semicircle of rotation, and negative values for the second, so you will need to account for that in your calculations.