我使用PDFView
来显示PDF。如果我快速滚动,我会发生内存泄漏。
let pdfView = PDFView.init(frame: CGRect.zero)
self.view.insertSubview(pdfView, belowSubview: bottomBar)
pdfView.snp.makeConstraints { (make) in
make.top.equalTo(topBar.snp.bottom).offset(8)
make.left.equalTo(8)
make.right.equalTo(-8)
make.bottom.equalTo(-54)
}
let url = Bundle.main.url(forResource: "swift", withExtension: "pdf")!
let doc = PDFDocument.init(url: url)
pdfView.document = doc
if let page = doc?.page(at: 0) {
let rect = page.bounds(for: .mediaBox)
let scale = (UIScreen.width - 16) / rect.width
pdfView.minScaleFactor = scale
pdfView.maxScaleFactor = scale
pdfView.scaleFactor = scale
pdfView.displaysPageBreaks = true
pdfView.pageBreakMargins = UIEdgeInsets.init(top: 0, left: 0, bottom: 8/scale, right: 0)
pdfView.layoutDocumentView()
}
查看记忆图图像
答案 0 :(得分:0)
您可以尝试在WebView中显示PDF吗?
这样的事情:
let url = yourLocalURL
webView.loadRequest(URLRequest(url: URL(string: url)!))