【问题标题】:PDF-Scrollview - show PDF - document in landscape formatPDF-Scrollview - 显示 PDF - 横向格式的文档
【发布时间】:2011-09-04 13:05:15
【问题描述】:

我正在使用 Apple 的示例 «PDFScrollView» 在 iPad 上显示 PDF。只要 PDF 文档处于纵向模式,它就可以正常工作。 但是,当文档处于横向模式时,文档始终显示为旋转 90 度。 我找到了这个How to detect the orientation of a PDF document in iPhone SDK - 但是当我尝试获取 PDF 的尺寸时,高度总是大于宽度,无论 PDF 的方向是什么......

有什么想法吗?

【问题讨论】:

    标签: iphone pdf uiscrollview orientation


    【解决方案1】:

    如前所述,CGPDFPageGetBoxRect(page, kCGPDFMediaBox) 始终为 PDF 返回相同的大小,无论 PDF 的方向如何。

    但是页面的旋转是正确返回的。

    所以我使用以下代码进行轮换:

    rotate =  CGPDFPageGetRotationAngle(page);
    

    然后使用我在这里找到的以下代码:http://ipdfdev.com/2011/03/23/display-a-pdf-page-on-the-iphone-and-ipad/

    switch (rotate) {
            case 0:
                // Translate the origin of the coordinate system at the 
                // bottom left corner of the page rectangle.
                CGContextTranslateCTM(context, 0, cropBox.size.height);
                // Reverse the Y axis to grow from bottom to top.
                CGContextScaleCTM(context, 1, -1);
                break;
            case 90:
                // Reverse the Y axis to grow from bottom to top.
                CGContextScaleCTM(context, 1, -1);
                // Rotate the coordinate system.
                CGContextRotateCTM(context, -M_PI / 2);
                break;
            case 180:
            case -180:
                // Reverse the Y axis to grow from bottom to top.
                CGContextScaleCTM(context, 1, -1);
                // Translate the origin of the coordinate system at the 
                // top right corner of the page rectangle.
                CGContextTranslateCTM(context, cropBox.size.width, 0);
                // Rotate the coordinate system with 180 degrees.
                CGContextRotateCTM(context, M_PI);
                break;
            case 270:
            case -90:
                // Translate the origin of the coordinate system at the 
                // bottom right corner of the page rectangle.
                CGContextTranslateCTM(context, cropBox.size.height, cropBox.size.width);
                // Rotate the coordinate system.
                CGContextRotateCTM(context, M_PI / 2);
                // Reverse the X axis.
                CGContextScaleCTM(context, -1, 1);
                break;
        }
    

    等等 - PDF 以正确的方向显示

    【讨论】:

      【解决方案2】:

      我写这篇文章的假设是您的问题是关于当用户旋转设备时旋转文档.... 为此,您必须在视图中重绘文档。要实现这一点,请执行以下操作....

      1. 更改绘制文档的视图的框架,并在以下方法中在该视图中使用 CALayer(OR CATiledLayer)。 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

      2. 换帧后调用CATiledLayer的setNeedsDisplay方法。

      3. 然后返回YES - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

      以上步骤将相应地在您查看的新框架中重新绘制文档,以便它正确显示。

      ->如果你的视图是全屏的,或者只有第 2 步和第 3 步就足够了。

      如果需要任何进一步的帮助,请在此处发布....

      【讨论】:

      • 感谢您的回答 - 但不幸的是,您的假设是错误的。 PDF 以横向保存,因此无论设备的方向如何,文档都会以 90 度旋转显示。加载 PDF 时,它最初会以这种旋转方式显示,并且即使设备旋转时也会保持这种状态......
      • 我为不相关的答案道歉。根据我的信息,PDF 文档是一组在上下文中绘制图形的命令......所以它们没有任何方向的概念。它们将以创建时的方式出现。现在我可以在这里提出一个建议。如果文档显示不正确,请为用户提供一个用于旋转文档的按钮。当用户单击时,您可以使用 CGAffineTransform 旋转它。访问此链接以旋转您的视图。 stackoverflow.com/q/356882/919049
      【解决方案3】:

      您自己绘制 PDF 是否有特殊原因?您可以在 iOS 4.0 或更高版本上使用 QLPreviewController,在以前的版本上使用 UIDocumentInteractionController

      【讨论】:

      • 我不得不承认,我从来没有听说过这两个...乍一看看起来很有希望 - 虽然我需要一些特殊的东西,比如书签,但这也可以工作......谢谢!
      • 好吧 - 看了之后,这并不是我真正需要的。我需要能够跳转到文档中的特定页面,为页面设置书签等等......据我所知,QLPreviewController 不提供任何分页或书签。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      相关资源
      最近更新 更多