Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS12上拍摄PDF查看器的快照_Ios_Swift - Fatal编程技术网

在iOS12上拍摄PDF查看器的快照

在iOS12上拍摄PDF查看器的快照,ios,swift,Ios,Swift,下午好 我正在尝试拍摄PDF的快照,但在iOS 12上访问view的内容时遇到了一些困难 为了显示PDF的内容,我已经使用了两种不同的方法: UIDocumentInteractiorController 网络视图 在iOS 11上,我还不能拍摄UIDocumentInteractiorController视图的快照,我能找到的最好答案就是这个。简而言之,它说文档查看器在一个外部进程中运行,在主应用程序进程无法访问的自己的窗口中运行 在iOS 12问世之前,WebView是当时的解决方案。在

下午好

我正在尝试拍摄PDF的快照,但在iOS 12上访问view的内容时遇到了一些困难

为了显示PDF的内容,我已经使用了两种不同的方法:

  • UIDocumentInteractiorController
  • 网络视图
在iOS 11上,我还不能拍摄UIDocumentInteractiorController视图的快照,我能找到的最好答案就是这个。简而言之,它说文档查看器在一个外部进程中运行,在主应用程序进程无法访问的自己的窗口中运行

在iOS 12问世之前,WebView是当时的解决方案。在运行iOS 12的真实设备上进行测试时,我遇到了同样的问题,拍摄快照时无法访问查看器的内容。在检查视图层次结构时,看起来我们有一个childviewcontroller(PDFHostViewController),它是渲染实际视图的控制器

请注意,此问题仅发生在PDF上,在常规网页上运行良好

用于拍摄快照的代码:

private extension UIView {

    func takeSnapshot() -> UIImage {
        let format = UIGraphicsImageRendererFormat()
        format.opaque = self.isOpaque
        let renderer = UIGraphicsImageRenderer(size: self.frame.size, format: format)
        return renderer.image { context in
            self.drawHierarchy(in: self.frame, afterScreenUpdates: true)
        }
    }

}

注意:我也尝试使用本机网络视图。网络视图的快照(带有:,completionHandler),但它只适用于常规网页,而不适用于PDF

可能适用于苹果的PDFKit。据我所知,PDFView是UIView的一个子类

import PDFKit

@IBOutlet var pdfView: PDFView!

let pdfDocument = PDFDocument(url: url)
pdfView.document = pdfDocument
然后您的扩展名为PDFView扩展名