Rotate UIView around its center keeping its size

Diego Acosta picture Diego Acosta · Jan 27, 2014 · Viewed 68.9k times · Source

I'm trying to rotate an UIView a few radians but after applying the transformation it doesn't look to be keeping its size. What's the proper way to achieve this?

Here's what I'm doing and what I get (Blue box with the arrow is the View I'm trying to rotate -- it should keep same aspect as red box behind):

#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)

double rads = DEGREES_TO_RADIANS(240);
CGAffineTransform transform = CGAffineTransformRotate(CGAffineTransformIdentity, rads);
self.arrowView.transform = transform;

enter image description here

Thanks!

Answer

Shaheen Ghiassy picture Shaheen Ghiassy · Aug 3, 2015

I avoid using macros unless necessary. This works perfectly well

float degrees = 20; //the value in degrees
view.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);