4

Im working on an application that needs to display a pretty large PDF file. I'm using PDFKits PDFView for this, which is then wrapped in a UIViewRepresentable. The problem is that when setting PDFView.autoScales = true i get an error on startup. The application still works and so does the autoScales feature but I would still like to fix the error. I should also mention that I'm a complete beginner when it comes to iOS development.

This is my implementation of makeUIView:

func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
    let pdfView = PDFView()
    pdfView.autoScales = true
    pdfView.pageBreakMargins.top = 0.0
    pdfView.pageBreakMargins.bottom = 0.0
    pdfView.pageShadowsEnabled = false
    pdfView.document = PDFDocument(url: self.url)        
    return pdfView
}

And this is the error:

[Assert] -[UIScrollView _clampedZoomScale:allowRubberbanding:]: Must be called with non-zero scale
[Unknown process name] CGAffineTransformInvert: singular matrix.

They seem to get printed whenever the PDFView gets initialized. Any ideas what the problem could be?

2 Answers2

6

I have meet the same issue, and I have fixed now.

Your pdfView should set the frame first.You can give any value.

let pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))   
self.view.addSubview(pdfView)

It is OK now, and then solve the error

Mahmoud
  • 9,729
  • 1
  • 36
  • 47
li ao
  • 61
  • 1
  • 4
  • Didn't get rid of the error for me. Is this for SwiftUI? Like the others, I'll ignore. – SPM Jul 04 '23 at 01:11
0

I ended up just ignoring it. Seems to work fine.