tags:

views:

122

answers:

1

Hi,

How can one image be rotated with axis of rotation as image centre using NSAffineTransform.

+2  A: 

You need to translate the origin to the point you want to rotate around, do the rotation and then translate the origin back:

@implementation NSAffineTransform (Rotation)
+ (NSAffineTransform *)transformRotatingAroundPoint:(NSPoint) p byDegrees:(CGFloat) deg
{
    NSAffineTransform * transform = [NSAffineTransform transform];
    [transform translateXBy: p.x yBy: p.y];
    [transform rotateByDegrees:deg];
    [transform translateXBy: -p.x yBy: -p.y];
    return transform;
}
@end
Rob Keniger
Thanks Rob for ur suggestion. It did work out.
iSight
How can I rotate the image when user moves touches on iphone? Any tutorial or code or URL or example?
Satyam svv