25

I can not figure out how to use CATransform3DMakeRotation(). Can somebody please tell me how to use it?

I think the first parameter is the angle, right? But what are the other three?

mfaani
  • 33,269
  • 19
  • 164
  • 293
Daniel Node.js
  • 6,734
  • 9
  • 35
  • 57

3 Answers3

40

The first is the angle in radians the other 3 parameters are the axis (x, y, z). So for example if you want to rotate 180 degrees around the z axis just call the function like this:

myView.layer.transform = CATransform3DMakeRotation(M_PI, 0.0, 0.0, 1.0);

and apply the result to the transform property of the view you want to rotate.

Gu1234
  • 3,466
  • 3
  • 23
  • 24
  • 1
    See also the Core Animation Function Reference for the definition of the function: https://developer.apple.com/documentation/quartzcore/1436558-catransform3dmakerotation?language=objc – Brad Larson Jan 02 '11 at 01:40
  • so basically i just set the angle and put 1.0 on the x, y, or, z that i want to use? is it always 1.0? – Daniel Node.js Jan 02 '11 at 02:55
  • 4
    @Dan - No, it's not always 1.0 for the axes. The X, Y, and Z components define an axis about which rotation takes place. Setting 1.0 for a component, and leaving the other to at 0.0, defines a rotation about the X, Y, or Z axis, but you can rotate about any arbitrary direction. This lets you manipulate views and layers in a truly 3-D manner. – Brad Larson Jan 02 '11 at 06:13
7

You'll probably find these useful when using radians:

CGFloat DegreesToRadians(CGFloat degrees)
{
  return degrees * M_PI / 180;
};

CGFloat RadiansToDegrees(CGFloat radians)
{
  return radians * 180 / M_PI;
};
ScottWasserman
  • 1,700
  • 1
  • 11
  • 8
3

They represent the axis about which you want to rotate. Use 0,0,1 to rotate in the plane of the screen.

mvds
  • 45,755
  • 8
  • 102
  • 111