I'm using CATiledLayer to render a heavy pdf page inside a UIScrollView that is used to handle zooming and spanning..
The method below is called every time a Tile need to be drawn and I regret that I have to paint the whole pdf every time. I hope that behind the scene the CATiledLayer only render the part that it needs but nothing is less sure at the moment.
- (void)drawLayer: (CALayer*)layer inContext: (CGContextRef) context {
[super drawLayer:layer inContext:context];
CGRect box = CGContextGetClipBoundingBox(context);
CGContextSetGrayFillColor(context, 1.0, 1.0);
CGContextFillRect(context, box);
CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, layer.bounds, 0, true));
CGContextDrawPDFPage(context, pdfPage);
}
I can determine the Tile coordinate using following code
CATiledLayer* castedLayer = (CATiledLayer*)layer;
CGSize tileSize = [castedLayer tileSize];
CGRect box = CGContextGetClipBoundingBox(context);
CGFloat x = box.origin.x / tileSize.width;
CGFloat y = box.origin.y / tileSize.height;
but can't find a way to only render the part of the pdf that is usefull for that Tile
Could someone either explain how I can render only the part of the pdf that I need or explain why it is not necessary on a performance point of view.