Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS, how to clear context graphics

In my app I have a method that draws a pdf into a context:

 CGPDFPageRef page = CGPDFDocumentGetPage(pdf, index + 1);

 CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(page, kCGPDFTrimBox),
                                                          CGContextGetClipBoundingBox(ctx));

 CGContextConcatCTM(ctx, transform);

 CGContextDrawPDFPage(ctx, page);

Now in drawLayer, that is called when zooming, I do the necessary transformations and call again CGContextDrawPDFPage(ctx, page);

What happens is that a zoomed pdf is drawn on top of the first pdf, the problem is that in a particular page with only text, the back and blurred pdf is shown. That is strange, I thought that pdf page had white background and if this happens it's because the zoomed pdf on top has transparent background.

Now, to solve this how can I clear the context right before the CGContextDrawPDFPage(ctx, page) of drawLayer method? I tried:

//self.view.transform = CGAffineTransformIdentity;

//CGAffineTransform transform = CGAffineTransformIdentity;
//CGContextConcatCTM(ctx, transform);

//CGContextClearRect(ctx, layer.bounds);

Nothing works...thanks in advance

like image 392
lopes710 Avatar asked Mar 15 '12 10:03

lopes710


1 Answers

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.bounds);
like image 122
Will Avatar answered Oct 04 '22 21:10

Will