iOS PDFView causes underlying assertion when autoScales is set to true

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?

Upvotes: 5

Views: 1614

Answers (2)

li ao
li ao

Reputation: 71

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

Upvotes: 7

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

Upvotes: 0

Related Questions