views:

54

answers:

2

how to rotate CALayer at one selected point.

@all Thanks in advance.

A: 

Check out the CA documentation here:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreAnimation_functions/Reference/reference.html

You want to set the transform to a CATransform3DRotate, for example:

CATransform3D current = myLayer.transform;
myLayer.transform = CATransform3DRotate(current, DEGREES_TO_RADIANS(20), 0, 1.0, 0);
Ben
This will only suffice for rotating the layer about its current center, not an arbitrary point.
warrenm
+1  A: 
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, rotationPoint.x-center.x, rotationPoint.y-center.y, 0.0);
transform = CATransform3DRotate(transform, rotationAngle, 0.0, 0.0, -1.0);
transform = CATransform3DTranslate(transform, center.x-rotationPoint.x, center.y-rotationPoint.y, 0.0);

Where center is the center of your layer, rotationAngle is in radians (positive is counterclockwise), and rotationPoint is the point about which you wish to rotate. center and rotationPoint are in the coordinate space of the containing view.

warrenm
Thanks warrenm its working.......
kiran kumar