在UIWebView中打开时pdf出现问题 [英] Problem with pdf while opening in UIWebView

查看:123
本文介绍了在UIWebView中打开时pdf出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UIWebView中打开pdf时出现问题.放大和缩小不起作用,甚至连按两次都不能放大pdf字体大小.
伙计们有什么办法做到......
如果不能,那么任何人都可以共享一些代码....

I have a problem while opening a pdf in a UIWebView. Zoom in and Zoom out doesn't work and even double tap doesn't enlarge the pdf font size.
Guys is there any way to do that....
If not can anyone share some code ....

推荐答案


    #import 


    @interface TiledPDFView :  UIView {
        CGPDFPageRef pdfPage;
        CGFloat myScale;

    }

    - (id)initWithFrame:(CGRect)frame andScale:(CGFloat)scale;
    - (void)setPage:(CGPDFPageRef)newPage;

    @end



    #import "TiledPDFView.h"
    #import 

    @implementation TiledPDFView


    // Create a new TiledPDFView with the desired frame and scale.
    - (id)initWithFrame:(CGRect)frame andScale:(CGFloat)scale{
        if ((self = [super initWithFrame:frame])) {

            CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];

            tiledLayer.levelsOfDetail = 4;
            tiledLayer.levelsOfDetailBias = 4;
            tiledLayer.tileSize = CGSizeMake(512.0, 512.0);
            myScale = scale;
        }
        return self;
    }

    // Set the layer's class to be CATiledLayer.
    + (Class)layerClass {
        return [CATiledLayer class];
    }

    // Set the CGPDFPageRef for the view.
    - (void)setPage:(CGPDFPageRef)newPage
    {
        CGPDFPageRelease(self->pdfPage);
        self->pdfPage = CGPDFPageRetain(newPage);
    }

    -(void)drawRect:(CGRect)r
    {
        // UIView uses the existence of -drawRect: to determine if it should allow its CALayer
        // to be invalidated, which would then lead to the layer creating a backing store and
        // -drawLayer:inContext: being called.
        // By implementing an empty -drawRect: method, we allow UIKit to continue to implement
        // this logic, while doing our real drawing work inside of -drawLayer:inContext:
    }


    // Draw the CGPDFPageRef into the layer at the correct scale.
    -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
    {
        // First fill the background with white.
        CGContextSetRGBFillColor(context, 1.0,1.0,1.0,0.5);
        CGContextFillRect(context,self.bounds);

        CGContextSaveGState(context);
        // Flip the context so that the PDF page is rendered
        // right side up.
        CGContextTranslateCTM(context, 0.0, self.bounds.size.height);


        // Scale the context so that the PDF page is rendered 
        // at the correct size for the zoom level.
        CGContextScaleCTM(context, myScale,myScale);    
        CGContextDrawPDFPage(context, pdfPage);
        CGContextRestoreGState(context);

    }

    // Clean up.
    - (void)dealloc {
        CGPDFPageRelease(pdfPage);

        [super dealloc];
    }


    @end

将此添加到您的项目中...
希望能有所帮助....

Add this to your project...
Hope it helped....

这篇关于在UIWebView中打开时pdf出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆