Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "rotate" a layer/view (e.g. just like you would in enigmo)

I know how to move a layer based on touch. But I would also like to be able to rotate the image.

Is there any sample code that shows how to do this? Or can anyone give me some advice?

Thanks!

like image 449
rksprst Avatar asked Oct 28 '08 07:10

rksprst


1 Answers

The simplest way to do this is using the layer's transform property:

float   angle = M_PI;  //rotate 180°, or 1 π radians
layer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0);

The first argument to the CATransform3DMakeRotation function is the amount to rotate, in radians. The next three describe the vector around which to rotate. This is describing a vector in the z-axis, so effectively perpendicular to the screen. This will rotate the layer so it's upside down.

like image 101
Ben Gottlieb Avatar answered Nov 15 '22 14:11

Ben Gottlieb