je suis un noob dans IPhone sdk.iPhone CatiledLayer pdf
Je tente de développer une lecture de pdf personnalisée en utilisant CatiledLayer mais j'ai beaucoup de problèmes. Je ne peux pas charger toutes les pages du document pdf donc j'essaie de tirer dynamiquement les pages, mais ce code de la fonction de tirage ne fonctionne pas:
- (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]);
}
}
cette fonction print seule la dernière page.
Une idée?
le nombre magique correct is't le code rigth est:
- (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;
}
Maintenant tout le travail !!