Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone UIView how to render a layer at a specific point?

I'm creating a pdf by hand and need to render a few images within a view. The images have their frames defined in a template nib file. However, I cannot seem to find a good way to render these images according to the frames that were assigned to them in the template file.

When I call

[imageView.layer renderInContext:pdfContext];

The view gets rendered with origin at 0,0.

UPDATE: The solution was to translate the origin of the coordinate system before rendering the context, and restore it after rendering

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);

How can I properly render a layer in graphics context with the correct origin, as defined within the view's frame.origin point?

like image 330
Alex Stone Avatar asked Nov 19 '25 03:11

Alex Stone


1 Answers

I needed to adjust the coordinate system before the operation

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);
like image 115
Alex Stone Avatar answered Nov 21 '25 17:11

Alex Stone