I am creating a PDFViewer application. I have set the autoScale Property of the PDFViewer to true, so that it the view expands to the width of the screen. Works fine with large PDF documents. But when the document is a single page document, the page automatically scrolls down to the end of the page, instead of starting with the beginning. I just cant understand the root cause of it. What am I missing here?
I think this is a bug in PDFView.
As workaround I suggest to manually scroll top the top:
self.pdfView.document = pdfDocument;
NSPoint pt = NSMakePoint(0.0, [self.pdfView.documentView bounds].size.height);
[self.pdfView.documentView scrollPoint:pt];
rdar://37942090: PDFview scrolls to bottom of the page in single page document.
I propose this solution for scrolling to top of first page (it works on iOS 11.3):
if let document = pdfView.document,
let firstPage = document.page(at: 0)
{
let firstPageBounds = firstPage.bounds(for: pdfView.displayBox)
pdfView.go(to: CGRect(x: 0, y: firstPageBounds.height, width: 1.0, height: 1.0), on: firstPage)
}
This is what I did, it's a bit hacky
if let scrollView = pdfView.subviews.first as? UIScrollView {
scrollView.contentOffset.y = 0.0
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With