iosuiscrollviewcatiledlayercgpdfdocumentcgpdfcontext

PDF zooming inside UIScrollView


I have a 2835 pixel PDF file inside 2835 pixel UIScrollView. To display the PDF I use CATiledLayer.

My problem is when I zoom out the scrollView (at scale below 1) the PDF quality gets very bad. What is strange that when I zoom in the scrollView (at scale above 1) the PDF looks great. The more I zoom in (scale*10) the better the quality.

How do I change the code so that both the downscale and upscale quality is good?

// Draw the CGPDFPageRef into the layer at the correct scale.
-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
{
// First fill the background with white.
//CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context,CGRectMake(0, 0, 2835,1417));

CGContextSetInterpolationQuality(context, kCGInterpolationHigh);

CGContextSaveGState(context);
// Flip the context so that the PDF page is rendered
// right side up.
CGContextTranslateCTM(context, 0.0, 1417);
CGContextScaleCTM(context, 1.0, -1.0);

// Scale the context so that the PDF page is rendered 
// at the correct size for the zoom level.
CGContextScaleCTM(context, myScale,myScale);    
CGContextDrawPDFPage(context, pdfPage);
CGContextRestoreGState(context);

}

Solution

  • I was setting both levelsOfDetail and levelsOfDetailBias to 10. This shifted all the zoom to upsaclaing. Now I changed levelsOfDetail to 10 and levelsOfDetailBias to 7 and all works ok.