如何更改文本旋转轴

car*_*los 0 iphone cocoa-touch core-graphics

CGContextShowText用来显示文本,但是当使用它旋转时CGAffineTransformation,旋转轴位于左侧,而不是绘制文本的中心,我使用的代码是:

CGContextSaveGState(context);

CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman);
CGContextSetCharacterSpacing (context, 1);
CGContextSetRGBFillColor (context, 0, 0, 0, 1);
CGAffineTransform xform = CGAffineTransformMake(
    sin(DegreesToRadians(angle)), cos(DegreesToRadians(angle)),
    cos(DegreesToRadians(angle)), -sin(DegreesToRadians(angle)),
    0,  0);

CGContextSetTextDrawingMode (context, kCGTextFill); 

CGPoint degreeDisplayPoint = CGPointMake(100,100);
CGContextShowTextAtPoint(context, degreeDisplayPoint.x, degreeDisplayPoint.y, [angleStringWithDegree cStringUsingEncoding:NSMacOSRomanStringEncoding], [angleStringWithDegree length]); 

CGContextRestoreGState(context);
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

MrZ*_*bra 5

翻译您的对象,使其中心位于(0,0),然后旋转它,然后将其转换回您想要的位置.