我正在尝试使用以下代码制作垂直滚动 PDFView:
pdfView = PDFView(frame: view.frame)
pdfView.backgroundColor = UIColor.white
var documentName: String = "test"
if let documentURL = Bundle.main.url(forResource: documentName, withExtension: "pdf") {
if let document = PDFDocument(url: documentURL) {
pdfView.displayDirection = .vertical
pdfView.usePageViewController(true, withViewOptions: nil)
pdfView.document = document
}
}
self.view.addSubview(pdfView)
它显示正常,但 displayDirection 是水平的,而不是垂直的。我正在尝试找到一种设置 withViewOptions 的方法,但我找不到这方面的相关信息。
我检查了 SO,很多人建议添加displayDirection
,但这并没有改变任何东西。
另一方面,当我尝试运行以下代码时:
pdfView = PDFView(frame: view.frame)
pdfView.backgroundColor = UIColor.white
var documentName: String = "test"
if let documentURL = Bundle.main.url(forResource: documentName, withExtension: "pdf") {
if let document = PDFDocument(url: documentURL) {
pdfView.autoScales = true
pdfView.displayDirection = .vertical
pdfView.displayMode = .singlePage
pdfView.document = document
}
}
self.view.addSubview(pdfView)
它只显示第一页,不滚动。我需要添加滑动手势识别器并且滚动不流畅。此外,单页滚动功能似乎有点矫枉过正......
我错过了什么吗?任何帮助将不胜感激!