【问题标题】:iOS - display PDF in a different OrientationiOS - 以不同的方向显示 PDF
【发布时间】:2013-09-08 11:26:47
【问题描述】:

我正在使用以下代码在 UIView 中显示 PDF

它是一个简单的应用程序,显示单个 PDF(这就是我所需要的)并且我正在单独处理缩放:我遇到的问题是当 iPad 更改为横向时,一切都被扭曲了 - 任何帮助我应该看哪里?/我应该怎么做才能处理方向问题?

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

【问题讨论】:

    标签: ios pdf uiview landscape uiinterfaceorientation


    【解决方案1】:

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

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

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

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

    UIView.contentMode = UIViewContentModeScaleAspectFill;
    

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

    【讨论】:

      猜你喜欢
      • 2016-01-31
      • 1970-01-01
      • 2012-01-22
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多