Configuring Scroll Directions and Page Transitions in Our Viewer
You can configure the page transition, scroll direction, and scroll mode of a PDFViewController
in PDFConfiguration
(see the PDF configuration guide for more information).
In SettingsExample
from the Catalog app, you’ll see a complete example of how these properties interact together in the context of a PDFSettingsViewController
(opens in a new tab). A PDFSettingsViewController
(opens in a new tab) is used to change key UX settings that are configurable via the PDFConfiguration.settingsOptions
(opens in a new tab) property.

Recommended Configurations
For the best user experience, we recommend using one of the following two combinations of settings.
Book/Magazine-Style Scrolling
let configuration = PDFConfiguration { builder in builder.scrollDirection = .horizontal builder.pageTransition = .scrollPerSpread builder.pageMode = .automatic builder.spreadFitting = .fit}
This will show two pages at a time when there is sufficient space (typically on iPad in landscape), and one page at a time in all other situations.
Continuous Vertical Scrolling
let configuration = PDFConfiguration { builder in builder.scrollDirection = .vertical builder.pageTransition = .scrollContinuous builder.pageMode = .single builder.spreadFitting = .adaptive}
This will show pages fit to the window size in most cases or filling the width on iPhone in landscape.
Valid Combinations
You need to be aware of the following constraints when using the PDFConfiguration
properties (pageTransition
(opens in a new tab), scrollDirection
(opens in a new tab), and pageMode
(opens in a new tab)) simultaneously.
Per-Spread Scrolling
If the page transition is PageTransition.scrollPerSpread
(opens in a new tab), there are no constraints:
- The
scrollDirection
(opens in a new tab) property can be eitherScrollDirection.horizontal
(opens in a new tab) orScrollDirection.vertical
(opens in a new tab). - The
pageMode
(opens in a new tab) property can bePageMode.single
(opens in a new tab),PageMode.double
(opens in a new tab), orPageMode.automatic
(opens in a new tab).
let configuration = PDFConfiguration { builder in // When the page transition is `scrollPerPage`. builder.pageTransition = .scrollPerSpread builder.scrollDirection = .vertical // Can also be `.horizontal`. builder.pageMode = .single // Can also be `.double` or `.automatic`.}
PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) { // When the page transition is `PSPDFPageTransitionScrollPerSpread`. builder.pageTransition = PSPDFPageTransitionScrollPerSpread; builder.scrollDirection = PSPDFScrollDirectionVertical; // Can also be `PSPDFScrollDirectionHorizontal`. builder.pageMode = PSPDFPageModeSingle; // Can also be `PSPDFPageModeDouble` or `PSPDFPageModeAutomatic`.}];
Continuous Scrolling
If the page transition is PageTransition.scrollContinuous
(opens in a new tab):
- The
scrollDirection
(opens in a new tab) property can be eitherScrollDirection.horizontal
(opens in a new tab) orScrollDirection.vertical
(opens in a new tab). - If
ScrollDirection.vertical
(opens in a new tab) is used, thepageMode
(opens in a new tab) property can bePageMode.single
(opens in a new tab),PageMode.double
(opens in a new tab), orPageMode.automatic
(opens in a new tab). It’ll be forced toPageMode.single
(opens in a new tab) ifScrollDirection.horizontal
(opens in a new tab) is used.
let configuration = PDFConfiguration { builder in // When the page transition is `scrollContinuous`. builder.pageTransition = .scrollContinuous builder.scrollDirection = .vertical // Can also be `.horizontal`. builder.pageMode = .single // Setting a value to `pageMode` will only be honored if `scrollDirection` is `.vertical`. It will be forced to single otherwise.}
PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) { // When the page transition is `PSPDFPageTransitionScrollContinuous`. builder.pageTransition = PSPDFPageTransitionScrollContinuous; builder.scrollDirection = PSPDFScrollDirectionVertical; // Can also be `PSPDFScrollDirectionHorizontal`. builder.pageMode = PSPDFPageModeSingle; // Setting a value to `pageMode` will only be honored if `scrollDirection` is `PSPDFScrollDirectionVertical`. It will be forced to `PSPDFPageModeSingle` otherwise.}];
Page Curl
If the page transition is PageTransition.curl
(opens in a new tab):
- The value of
scrollDirection
(opens in a new tab) will be forced toScrollDirection.horizontal
(opens in a new tab). - The
pageMode
(opens in a new tab) property can bePageMode.single
(opens in a new tab),PageMode.double
(opens in a new tab), orPageMode.automatic
(opens in a new tab).
let configuration = PDFConfiguration { builder in // When the page transition is `curl`. builder.pageTransition = .curl builder.scrollDirection = .horizontal // Setting a value to the `scrollDirection` property will be ignored. It will be forced to `.horizontal`. builder.pageMode = .single // Can also be `.double` or `.automatic`.}
PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) { // When the page transition is `PSPDFPageTransitionCurl`. builder.pageTransition = PSPDFPageTransitionCurl; builder.scrollDirection = PSPDFScrollDirectionHorizontal; // Setting a value to the `scrollDirection` property will be ignored. It will be forced to `PSPDFScrollDirectionHorizontal`. builder.pageMode = PSPDFPageModeSingle; // Can also be `PSPDFPageModeDouble` or `PSPDFPageModeAutomatic`.}];
Persisting the Settings Options with User Defaults
You can persist the settings options for your PDFSettingsViewController
(opens in a new tab) in your app’s UserDefaults
(opens in a new tab).
Saving the Settings Options
You can save the settings in your app’s user defaults in PDFViewControllerDelegate.pdfViewControllerDidDismiss(_:)
(opens in a new tab), like so:
func pdfViewControllerDidDismiss(_ pdfController: PDFViewController) { // Persist the settings options in the user defaults. let defaults = UserDefaults.standard defaults.set(pdfController.configuration.pageTransition.rawValue, forKey: "pageTransition") defaults.set(pdfController.configuration.pageMode.rawValue, forKey: "pageMode") defaults.set(pdfController.configuration.scrollDirection.rawValue, forKey: "scrollDirection") defaults.set(pdfController.configuration.spreadFitting.rawValue, forKey: "spreadFitting")}
- (void)pdfViewControllerDidDismiss:(PSPDFViewController *)pdfController { // Persist the settings options in the user defaults. NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults; [defaults setInteger:pdfController.configuration.pageTransition forKey: @"pageTransition"]; [defaults setInteger:pdfController.configuration.pageMode forKey: @"pageMode"]; [defaults setInteger:pdfController.configuration.scrollDirection forKey: @"scrollDirection"]; [defaults setInteger:pdfController.configuration.spreadFitting forKey: @"spreadFitting"];}
Restoring the Settings Options
You can restore the saved settings options from your app’s user defaults in your PDFConfiguration
, as seen below:
let configuration = PDFConfiguration { builder in // Restore the settings from the user defaults. let defaults = UserDefaults.standard builder.pageTransition = PageTransition(rawValue: UInt(defaults.integer(forKey: "pageTransition")))! builder.pageMode = PageMode(rawValue: UInt(defaults.integer(forKey: "pageMode")))! builder.scrollDirection = ScrollDirection(rawValue: UInt(defaults.integer(forKey: "scrollDirection")))! builder.spreadFitting = PDFConfiguration.SpreadFitting(rawValue: defaults.integer(forKey: "spreadFitting"))!}
PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) { // Restore the settings from the user defaults. NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults; builder.pageTransition = [defaults integerForKey:@"pageTransition"]; builder.pageMode = [defaults integerForKey:@"pageMode"]; builder.scrollDirection = [defaults integerForKey:@"scrollDirection"]; builder.spreadFitting = [defaults integerForKey:@"spreadFitting"];}];
For more details and sample code, take a look at PersistViewSettingsExample.swift
(opens in a new tab) from the Catalog app.