gpt4 book ai didi

iphone - 在 UIWebView 中打开 pdf 时出现问题

转载 作者:行者123 更新时间:2023-12-03 20:53:55 25 4
gpt4 key购买 nike

我在 UIWebView 中打开 pdf 时遇到问题。放大和缩小不起作用,甚至双击也无法放大 pdf 字体大小。
伙计们有什么办法可以做到这一点......
如果没有,任何人都可以分享一些代码......

最佳答案


#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

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

关于iphone - 在 UIWebView 中打开 pdf 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6676943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com