我使用 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);

有什么想法吗?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top