Rotating an image with the image centre as axis of rotation
How can one image be rotated with axis of rotation as image centre using NSAffineTrans开发者_开发问答form.
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
精彩评论