views:

43

answers:

1

Hi guys,

I'm rotating a CALayer on the X axis, but even if it's displaced on the Z axis, it uses the Z = 0 as axis for the rotation?

Is there a way of telling it to use the bottom of the plane, as the axis?

Thank you!

+2  A: 

The transform of a CALayer uses the layer's anchor as its origin. You could try adjusting the anchorPoint and anchorPointZ properties of the layer.

Kevin Ballard
Thanks. I haven't got it working exactly as I wanted yet, but that certainly helped. You wouldn't happen to know how to determine the layer's current X rotation, would you? Cheers :)
Andre
A transform is just a struct representing a matrix. You can do some math with the underlying floats to figure out the rotation, but I don't know what it is off the top of my head. Wikipedia can probably help, search for Affine Transform.
Kevin Ballard
Are you sure Kevin? I was under the impression Affine Transformations only allow 2D operations, including skew, but no perspective. Cheers
Andre
Affine transforms are 2D, which is what UIView exposes, but CALayer exposes a 3D transform. The `transform` property of CALayer is a `CATransform3D`, but it has an `-affineTransform` method that returns the CGAffineTransform that best represents the CATransform3D. There's also the functions `CATransform3DIsAffine()`, `CATransform3DMakeAffineTransform()`, and `CATransform3DGetAffineTransform()`.
Kevin Ballard
Actually that's not strictly true. It would be more accurate to say the classical idea of an affine transform (and what UIView exposes, and the type `CGAffineTransform`) is a 2D transformation, but affine transforms actually map between two vector spaces, so `CATransform3D` is an affine transform in 3 dimensions.
Kevin Ballard