Search code examples
iosswiftrotationcgaffinetransformcgrect

Determine rotation of a UIView in Swift


Is there a way to determine how far a UIView has been rotated in Swift? For example, the UIView is rotated by the user using a rotation gesture recognizer, and then later, outside the gesture recognizer callback function, I want to determine how many degrees (or radians) the UIView was rotated.

I think it can be done using CGRectGetMinX, CGRectGetMaxX, CGRectGetMinY and CGRectGetMaxY but is there a simpler way to do it?


Solution

  • atan2(view.transform.b, view.transform.a) should do the trick if the UIView was not skewed.