1
我是iPhone SDK的noob。iPhone CatiledLayer pdf
我嘗試使用CatiledLayer開發自定義PDF閱讀,但我遇到了很多問題。 我無法加載PDF文檔的所有頁面,所以我嘗試動態繪製網頁,但繪製函數的代碼不起作用:
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
CGContextSaveGState(ctx);
for(int i=0; i<4;i++)
{
CGContextRestoreGState(ctx);
CGContextSaveGState(ctx);
CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
CGContextTranslateCTM(ctx, -layer.bounds.size.width*((5-2*i)/12), layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform([[pages objectAtIndex:i] pagin], kCGPDFCropBox, layer.bounds, 0, true));
CGContextDrawPDFPage(ctx, [[pages objectAtIndex:i] pagin]);
}
}
此功能只打印了最後一頁。
有什麼想法?
幻數豈不等於正確 的分辯代碼:
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
//scrollView.scrollEnabled=NO;
//scrollView.alpha=0.2;
//[scrollView setContentOffset:scrollView.contentOffset animated:YES];
CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
if(attua==1)
{
CGContextSaveGState(ctx);
CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
CGContextTranslateCTM(ctx,layer.bounds.size.width*1/(2*[pages count]) -layer.bounds.size.width*[pages count]/(2*[pages count]), layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform([[pages objectAtIndex:0] pagin], kCGPDFCropBox, layer.bounds, 0, true));
CGContextDrawPDFPage(ctx, [[pages objectAtIndex:0] pagin]);
CGContextRestoreGState(ctx);
}
for(int i=1; i<[pages count];i++)
{ //myContentView.frame=CGRectMake(0, 0,800*i, 1024);
if(i>attua-2)
{
if(i<attua+2)
{
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx,layer.bounds.size.width*(i*2+3/2)/(2*[pages count]) -layer.bounds.size.width*[pages count]/(2*[pages count]), layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform([[pages objectAtIndex:i] pagin], 0, layer.bounds, 0, true));
CGContextDrawPDFPage(ctx,[[pages objectAtIndex:i] pagin]);
CGContextRestoreGState(ctx);
}
}
}
scrollView.scrollEnabled=YES;
}
現在所有的工作!