5

How can I disable zooming on PDFView?

I've already tried the solution here, but it didn't work. I can still zoom in and zoom out.

Here's my PDFView:

let pdfView: PDFView = {
    let pdfView = PDFVIew()
    let urlPath = Bundle.main.path(forResource: "PdfFile", ofType: "pdf")
    let url = URL(fileURLWithPath: urlPath!)
    pdfView.document = PDFDocument(url: url)
    pdfView.autoScales = true
    pdfView.displayMode = .singlePageContinuous
    pdfView.displayDirection = .vertical
    pdfView.pageShadowsEnabled = false
    return pdfView
}()
ataravati
  • 8,891
  • 9
  • 57
  • 89

1 Answers1

9

Add following line of code will disable zoom of PDFView.

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    pdfView.minScaleFactor = pdfView.scaleFactor
    pdfView.maxScaleFactor = pdfView.scaleFactor
}
Sagar Chauhan
  • 5,715
  • 2
  • 22
  • 56
  • This worked. Thanks a lot! I used to do `pdfView.maxScaleFactor = pdfView.scaleFactorForSizeToFit` and didn't work. – ataravati Sep 09 '19 at 15:03
  • 2
    This is worked because you don't want to zoom pdf view at all, and you are trying to set `minScaleFactor ` & `maxScaleFactor` in `viewDidLoad` which are not completely render. In `viewDidAppear` `pdfView` completely render and give actual `scaleFactor`. So setting it to `minScaleFactor ` & `maxScaleFactor` preventing zooming. That's all. – Sagar Chauhan Sep 10 '19 at 05:34
  • @ataravati, You should accept bounty due to this is proper solution for you. – Sagar Chauhan Sep 10 '19 at 09:41
  • it doesn't let you accept bounty until 8 hours after. That's why I hadn't accepted it until now. – ataravati Sep 10 '19 at 13:54