CALayer and Off-Screen Rendering

人盡茶涼 提交于 2019-11-28 21:57:37

As i mentioned above, CALayers don't render if they are offscreen.

I ended up not drawing the PDF directly to the layer but instead, rendered the PDF page to an image when i needed (renders 1 page plus and minus one of the focused page)

Here is the render code:

-(UIImage *)renderPDFPageToImage:(int)pageNumber//NSOPERATION?
{
 //you may not want to permanently (app life) retain doc ref

 CGSize size = CGSizeMake(x,y);     
 UIGraphicsBeginImageContext(size);
 CGContextRef context = UIGraphicsGetCurrentContext();

 CGContextTranslateCTM(context, 0, 750);
 CGContextScaleCTM(context, 1.0, -1.0);

 CGPDFPageRef page;  //Move to class member 

    page = CGPDFDocumentGetPage (myDocumentRef, pageNumber);
    CGContextDrawPDFPage (context, page);

 UIImage * pdfImage = UIGraphicsGetImageFromCurrentImageContext();//autoreleased
 UIGraphicsEndImageContext();
 return pdfImage;

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!