2010-07-15 2 views
1

나는 아이폰 SDK에 멍청하다.iPhone CatiledLayer pdf

저는 CatiledLayer를 사용하여 사용자 정의 PDF를 읽으려고 시도하지만 많은 문제가 있습니다. 나는 그래서 동적 페이지를 그릴하려고하지만 draw 함수의 코드가 작동하지 않는 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]); 

} 
} 

이 기능 인쇄 마지막 페이지를.

어떤 아이디어? '

매직 넘버가 올바른 일 아닌가요 rigth 코드는 다음과 같습니다

- (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; 







} 

이제 모든 작업!

답변

1

for 루프 주위에서 전체 컨텍스트에 대해 CGContextFillRect를 수행하는 것처럼 보이므로 기존 자료 (즉, 마지막 페이지를 제외하고 모두)를 비워야합니다.

저는 CATiledLayer에서 직접 PDF 도면 주위로 머리를 감싸려고합니다. 좌표계를 번역 할 때 "마술 번호"가있는 것 같습니다. (5-2 * i)/12이다. 나는이 페이지가 서로 나란히 놓여 있다고 가정합니다. 그 번호가 맞았는지 확실합니까?

관련 문제