【问题标题】:Pop translations used during CGContextCGContext 期间使用的 Pop 翻译
【发布时间】:2026-01-26 10:15:03
【问题描述】:

正如您在下面的代码中看到的,我在编写一些文本之前对我的 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));

【问题讨论】:

    标签: iphone objective-c xcode pdf cgcontext


    【解决方案1】:

    我认为 CGContextSaveGState(cntx) 和 CGContextRestoreGState(cntx) 是您正在寻找的。​​p>

    【讨论】: