开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜