在文本矩阵上使用多个CGAffineTransforms [英] Using Multiple CGAffineTransforms On Text Matrix
问题描述
我正在使用Quartz显示文本。这是我的代码:
I am displaying text using Quartz. Here is my code:
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGContextSelectFont(myContext, "Helvetica", 12, kCGEncodingMacRoman);
CGContextSetCharacterSpacing(myContext, 8);
CGContextSetTextDrawingMode(myContext, kCGTextFillStroke);
CGContextSetRGBFillColor(myContext, 0, 0, 0, 1);
CGContextSetRGBStrokeColor(myContext, 0, 0, 0, 1);
CGContextSetTextMatrix(myContext,CGAffineTransformMake(1, 0, 0, -1, 0, 0));
CGContextShowTextAtPoint(myContext, textOrigin.x, textOrigin.y,[way.name UTF8String],[way.name length]);
这会以正确的方向和正确的方向显示我的文本,但是我还需要添加一个使用 CGAffineTransformMakeRotation(angle);
旋转到文本。不过,我似乎无法弄清楚如何将两个仿射变换应用到文本矩阵,而又没有一个覆盖另一个。任何帮助都将非常有用。
This displays my text the right way up and in the right direction, however I also need to add a rotation to the text using CGAffineTransformMakeRotation(angle);
. I can't seem to work out how to aply two affine transforms to the text matrix, though, without one overwriting the other. Any help would be great.
推荐答案
您可以将矩阵与 CGAffineTransformConcat ,例如
CGAffineTransform finalTransf = CGAffineTransformConcat(t1, t2);
如果只需要对现有矩阵应用旋转,请使用 CGAffineTransformRotate ,例如
If you just need to apply rotation to an existing matrix, use CGAffineTransformRotate, e.g.
CGAffineTransform t = CGAffineTransformMake(1, 0, 0, -1, 0, 0);
CGAffineTransform t = CGAffineTransformRotate(t, M_PI/2);
CGContextSetTextMatrix(myContext, t);
这篇关于在文本矩阵上使用多个CGAffineTransforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!