1

I'm using the following code to display a PDF inside a UIView

Its a simple application, displaying a single PDF (which is all I need) and I"m handling zooming separately: The problem I'm having with this is when the iPad changes to Landscape everything is distorted - any help as to where I should look ? / what i should do to handle the orientation issue ?

- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();

//PDF might be transparent, assume white paper - set White Background
[[UIColor whiteColor] set];
CGContextFillRect(ctx, rect);

//Flip coordinates
CGContextGetCTM(ctx);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -rect.size.height);

//PDF File Path
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"TEST" withExtension:@"pdf"];
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfURL);
CGPDFPageRef page1 = CGPDFDocumentGetPage(pdf, 1);

//Get the rectangle of the cropped inside
CGRect mediaRect = CGPDFPageGetBoxRect(page1, kCGPDFCropBox);
CGContextScaleCTM(ctx, rect.size.width / mediaRect.size.width,
                  rect.size.height / mediaRect.size.height);

//Draw PDF
CGContextDrawPDFPage(ctx, page1);
CGPDFDocumentRelease(pdf);
}
4

1 回答 1

0

嗨,任何可能对此感兴趣的人。. .

这可能是最好的方法: Supporting two orientations with separate view controllers in iOS

以下问题讨论了如何注册设备方向更改,当检测到方向更改时,推送模式视图 - 显示带有尺寸的 PDF

其他选项可能如下:当您初始化 UIView 时,决定您希望它在方向改变时如何反应

UIView.contentMode = UIViewContentModeScaleAspectFill;

玩转各种 UIViewContentMode...:为您实现最佳效果当前允许重绘 PDF,保持其纵横比并填充屏幕的整个大小:因此它削减了大约一半的 PDF - - -

于 2013-09-14T16:33:54.957 回答