我想拥有我收到的东西
pdfView.autoScales = true
没有改变比例的可能性。
在@carmine 的帮助下,我们有:
import UIKit
import PDFKit
class ViewController: UIViewController {
@IBOutlet weak var pdfView: PDFView!
override func viewDidLoad() {
super.viewDidLoad()
setPdfFile()
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
self.pdfView.autoScales = true
}
func setPdfFile() {
if let path = Bundle.main.path(forResource: "Swift.org - Getting Started", ofType: "pdf") {
let url = URL(fileURLWithPath: path)
if let pdfDocument = PDFDocument(url: url) {
pdfView.autoScales = true
pdfView.displayMode = .singlePageContinuous
pdfView.displayDirection = .vertical
pdfView.document = pdfDocument
pdfView.displaysPageBreaks = false
pdfView.minScaleFactor = pdfView.scaleFactor
pdfView.maxScaleFactor = pdfView.scaleFactorForSizeToFit
}
}
}
}
这给出了这样的结果:https ://gfycat.com/briefpowerlessbug
但是,如果您在没有这些行的情况下运行:
pdfView.minScaleFactor = pdfView.scaleFactor
pdfView.maxScaleFactor = pdfView.scaleFactorForSizeToFit
您将收到我需要的结果,但需要进行缩放:https ://gfycat.com/presentconcretebunting
我想禁用缩放并使 pdfView 的宽度等于 pdf 文件的宽度。