Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide indicator scroll in PDFKit

Tags:

ios

swift

pdfkit

This is my PDFView config. I want to show PDF viewer with horizontal scroll, show single page.

But PDFView show the scroll indicator and it is not correct. I want to hide scroll indicator. My question is how to hide it or how to make its scroll position correct?

Horizontal scroll indicator visible at bottom of screen
pdfView.autoScales = true
pdfView.displaysPageBreaks = true
pdfView.displayMode = .singlePageContinuous
pdfView.usePageViewController(true)
pdfView.displayDirection = .horizontal
pdfView.minScaleFactor = 1
pdfView.document = pdfDocument
like image 737
omshanti Avatar asked Jul 07 '26 23:07

omshanti


1 Answers

Since PDFview is not giving access to its scrolling elements, the trick of accessing subviews of pdfview may work for you.

Chain of subviews when printed on console looks like:

(lldb) po pdfView.subviews
▿ 1 element
    - 0 : <_UIPageViewControllerContentView: 0x7fec7411d9f0; frame = (0 0; 414 808); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0x600001b33720>>

(lldb) po pdfView.subviews.first?.subviews.first
▿ Optional<UIView>
  - some : <_UIQueuingScrollView: 0x7fec7483aa00; frame = (0 0; 414 736); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x6000015153e0>; layer = <CALayer: 0x600001b33740>; contentOffset: {414, 0}; contentSize: {1242, 736}; adjustedContentInset: {0, 0, 0, 0}>

(lldb) 

So based on this, I have tested below code and it worked at my end. Try with code:

    let pdfScrollView = pdfView.subviews.first?.subviews.first as? UIScrollView
    pdfScrollView?.showsHorizontalScrollIndicator = false  // if pdf view scroll direction is horizontal
    pdfScrollView?.showsVerticalScrollIndicator = false // if pdf view scroll direction is vertical

Edit:

The view's hierarchy is been updated and scrollView is not at the first place Please refer answer from @Deepansh for getting scrollView object: https://stackoverflow.com/a/77080309/2677551

like image 183
Van Avatar answered Jul 10 '26 14:07

Van



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!