iPhone UIView 如何在特定点渲染图层



我正在手动创建一个pdf,需要在视图中渲染一些图像。图像的框架在模板笔尖文件中定义。但是,我似乎找不到一种好方法根据模板文件中分配给它们的帧来渲染这些图像。

当我打电话时

[imageView.layer renderInContext:pdfContext];

视图呈现时,原点为 0,0。

更新:解决方案是在渲染上下文之前平移坐标系的原点,并在渲染后恢复坐标系

CGContextTranslateCTM(pdfContext, imageView.frame.origin.x,imageView.frame.origin.y);
            //render the container, with the correct coordinate system
            [v.layer renderInContext:pdfContext];
            CGContextTranslateCTM(pdfContext, -imageView.frame.origin.x,-imageView.frame.origin.y);

如何在图形上下文中正确渲染具有正确原点的图层,如视图的 frame.原点中所定义?

我需要在操作前调整坐标系

CGContextTranslateCTM(pdfContext, imageView.frame.origin.x,imageView.frame.origin.y);
//render the container, with the correct coordinate system
[v.layer renderInContext:pdfContext];
CGContextTranslateCTM(pdfContext, -imageView.frame.origin.x,-imageView.frame.origin.y);

最新更新