【问题标题】:How to change Text Rotation Axis如何更改文本旋转轴
【发布时间】:2008-10-20 15:05:21
【问题描述】:

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

有什么想法吗?

【问题讨论】:

    标签: iphone cocoa-touch core-graphics


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-21
      • 2018-03-28
      • 2017-02-14
      • 2017-08-07
      • 1970-01-01
      • 2020-01-22
      • 2020-06-11
      相关资源
      最近更新 更多