CGContext 期间使用的流行翻译
正如您在下面的代码中看到的,我在编写一些文本之前对 UIView 进行了一些转换。文本的位置似乎受到上述转换的影响。
有没有办法“弹出”这些位移,以便我可以相对于原始 0,0 坐标编写文本?
//turn PDF upsidedown
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(100, aUIView.bounds.size.height+300);
transform = CGAffineTransformScale(transform, 0.5, -0.5);
CGContextConcatCTM(pdfContext, transform);
// Draw view into PDF
// Is renderInContext deprecated? Something to look into.
[aUIView.layer renderInContext:pdfContext];
CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
CGContextSetTextMatrix(pdfContext, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
const char *text = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG TEST 1";
CGContextShowTextAtPoint (pdfContext, 10.0, 10.0, text, strlen(text));
As you can see in the code below I do some transformations on my UIView before writing some text. It seems though that the position of the text is affected by the aforementioned transformations.
Is there any way to 'pop' these displacements so I can then write my text in relation to the original 0,0 coordinate?
//turn PDF upsidedown
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(100, aUIView.bounds.size.height+300);
transform = CGAffineTransformScale(transform, 0.5, -0.5);
CGContextConcatCTM(pdfContext, transform);
// Draw view into PDF
// Is renderInContext deprecated? Something to look into.
[aUIView.layer renderInContext:pdfContext];
CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
CGContextSetTextMatrix(pdfContext, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
const char *text = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG TEST 1";
CGContextShowTextAtPoint (pdfContext, 10.0, 10.0, text, strlen(text));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 CGContextSaveGState(cntx) 和 CGContextRestoreGState(cntx) 就是您正在寻找的。
I think CGContextSaveGState(cntx) and CGContextRestoreGState(cntx) are what you are looking for.