CATransform3DRotate flip horizontal

Nic Hubbard picture Nic Hubbard · Apr 28, 2012 · Viewed 9.3k times · Source

I have a layer that I need to transform. Currently I am using the following:

self.customLayer.transform = CATransform3DRotate(CATransform3DIdentity,M_PI / 2.0f, 0, 0, 1);

This correctly makes the layer right side up, but it also needs to be flipped horizontally, since it is the wrong way. How can I adjust CATransform3DRotate to do this?

Answer

joerick picture joerick · Apr 28, 2012

You'll need:

self.customLayer.transform = CATransform3DScale(CATransform3DMakeRotation(M_PI / 2.0f, 0, 0, 1),
                                                -1, 1, 1);

A scale with -1 is a flip. Imagine you're squashing the image horizontally and you go past zero.