Rotating a CALayer 90 degrees?

Kristina Brooks picture Kristina Brooks · Jul 29, 2010 · Viewed 34.7k times · Source

How do I rotate a CALayer 90 degrees? I need to rotate everything include sublayers and the coordinate system.

Answer

Jonathan Grynspan picture Jonathan Grynspan · Jul 29, 2010

Obj-C:

theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * M_PI, 0.0, 0.0, 1.0);

Swift:

theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * .pi, 0.0, 0.0, 1.0)

That is, transform the layer such that it is rotated by 90 degrees (π / 2 radians), with 100% of that rotation taking place around the z-axis.