2008-10-20 105 views
0

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

任何想法?

回答

5

翻譯您的對象,使其中心位於(0,0),然後旋轉它,然後將它翻譯回您想要的位置。