Configuring Scroll Views

Our PDF viewer relies on multiple scroll views to set up its complex view hierarchy. When these scroll views are configured, the document view controller calls two delegate methods for you to customize the scroll views or to set their delegate in.

You can start by setting the document view controller’s delegate:

pdfViewController.documentViewController?.delegate = ...

Then, implement one or two of the following delegate methods.

documentViewController(_:configureScrollView:) is called when the document view controller is configuring the scroll view responsible for scrolling the spreads.

documentViewController(_:configureZoom:forSpreadAt:), on the other hand, is called when the document view controller is configuring a scroll view responsible for zooming one or multiple spreads.

func documentViewController(_ documentViewController: PDFDocumentViewController, configureScrollView scrollView: UIScrollView) {
    // Here you can customize some of the scroll view's properties.
    scrollView.bounces = false
}

func documentViewController(_ documentViewController: PDFDocumentViewController, configureZoom zoomView: UIScrollView, forSpreadAt spreadIndex: Int) {
    // You can also set the delegate.
    zoomView.delegate = ...
}

Once you set a delegate of either one of the scroll views, you can implement standard UIScrollViewDelegate methods to be notified about a variety of events:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    print("New content offset:", scrollView.contentOffset)
}

For more information, refer to our guides on the document view hierarchy and handling user interactions.