首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone CatiledLayer pdf

iPhone CatiledLayer pdf
EN

Stack Overflow用户
提问于 2010-07-15 18:47:07
回答 1查看 929关注 0票数 1

我是IPhone软件开发工具包的新手。

我试着用CatiledLayer开发一个自定义的pdf阅读器,但我有很多问题。我不能加载pdf文档的所有页面,所以我尝试动态绘制页面,但此绘制函数的代码不起作用:

代码语言:javascript
复制
- (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]);

 }
}

此函数仅打印最后一页。

有什么想法吗?‘

魔术数字不正确,正确的代码是:

代码语言:javascript
复制
- (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;







}

现在一切正常了!!

EN

回答 1

Stack Overflow用户

发布于 2010-07-17 20:52:21

看起来你每次在for循环周围都要对整个上下文执行CGContextFillRect,从而清除了现有的材料(即除了最后一页之外的所有内容)。

我正在试着把我的头围绕在CATiledLayer绘图上。你似乎有一个转换坐标系的“魔术数字”;(5-2*i)/12。我想这是为了把页面排成一行。你确定这些数字是正确的吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3254809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档