我一直在做研究,因为我的pdf查看程序一直在4/5页附近崩溃,因为每次你翻一个页面时都会发生内存泄漏。
结果发现苹果有个窃听器。
见此处:https://devforums.apple.com/message/9077#9077
据我所知,每次更改页面时,您都必须发布并保留pdf文档。
我无法让它工作(这段代码位于UIView的子类中):
- (void) drawInContext: (CGContextRef) ctx {
CGPDFDocumentRelease(__pdfDoc);
CGContextSetRGBFillColor( ctx, 1.0, 1.0, 1.0, 1.0 );
CGContextFillRect( ctx, CGContextGetClipBoundingBox( ctx ));
CGContextTranslateCTM( ctx, 0.0, self.bounds.size.height );
CGContextScaleCTM( ctx, 1.0, -1.0 );
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, self.bounds, 0, true));
CGContextDrawPDFPage( ctx, pdfPage );NSLog(@"DONE!");
CGPDFDocumentRetain(__pdfDoc);}
@end我的pdf是在这里打开在一个viewController:
- (CGPDFPageRef) pdfPage: (NSInteger) index {
if( ! __pdfDoc ) {
__pdfDoc = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"mybook" ofType:@"pdf"]]);}
if( __pdfDoc ) {
size_t pdfPageCount = CGPDFDocumentGetNumberOfPages( __pdfDoc );
index++;
if( index < 1 )
index = 1;
if( index > pdfPageCount )
index = pdfPageCount;
CGPDFPageRef page = CGPDFDocumentGetPage( __pdfDoc, index );
return page;}
return nil;}我在google上找不到任何东西,我已经阅读了一整天的文档。
发布于 2010-08-23 20:51:39
嗯。虫子。绘制页面时,必须打开/关闭完整的文档。烂透了。
(我认为这是在3.2.x中修正的)
https://stackoverflow.com/questions/3551076
复制相似问题