【发布时间】:2021-01-03 16:23:50
【问题描述】:
我正在展示一些带有 PDFView 类的 PDF 文件。有一个问题是当我加载或更好地说替换另一个文件时,加载新文件时最后加载的文件仍然可见。
代码如下:
var pdfView = PDFView()
//MARK: - PDF KIT
func previewPDF(url:URL) {
if self.view.subviews.contains(pdfView) {
self.pdfView.removeFromSuperview() // Remove it
} else {
}
pdfView = PDFView(frame: PDFPreview.bounds)
pdfView.removeFromSuperview()
pdfView.backgroundColor = .clear
pdfView.displayMode = .singlePage
pdfView.autoScales = true
pdfView.pageShadowsEnabled = false
pdfView.document = PDFDocument(url: url)
thumbnail = PDFThumbnail(url: url, width: 240)
// I tried to nil PDFPreview, still nothing happened
PDFPreview.addSubview(pdfView)
}
【问题讨论】:
-
请您检查一下这个答案:- stackoverflow.com/a/53477567/3607051