Document Presentation Options

You can configure the page transition, scroll direction, and scroll mode of a PSPDFViewController in PSPDFConfiguration (see the PSPDFConfiguration 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 PSPDFSettingsViewController. A PSPDFSettingsViewController is used to change key UX settings that are configurable via the PSPDFConfiguration.settingsOptions property.

You need to be aware of the following constraints when using these PSPDFConfiguration properties (pageTransition, scrollDirection, and pageMode) simultaneously.

PSPDFPageTransitionScrollPerSpread

If the page transition is PSPDFPageTransitionScrollPerSpread, there are no constraints:

Copy
1
2
3
4
5
6
let configuration = PSPDFConfiguration { 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`.
}
Copy
1
2
3
4
5
6
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`.
}];

PSPDFPageTransitionScrollContinuous

If the page transition is PSPDFPageTransitionScrollContinuous:

Copy
1
2
3
4
5
6
let configuration = PSPDFConfiguration { 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.
}
Copy
1
2
3
4
5
6
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.
}];

PSPDFPageTransitionCurl

If the page transition is PSPDFPageTransitionCurl:

Copy
1
2
3
4
5
6
let configuration = PSPDFConfiguration { 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`.
}
Copy
1
2
3
4
5
6
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 Using UserDefaults

You can persist the settings options for your PSPDFSettingsViewController in your app’s UserDefaults.

Saving the Settings Options

You can save the settings in your app’s user defaults in -[PSPDFViewControllerDelegate pdfViewControllerDidDismiss:], like so:

Copy
1
2
3
4
5
6
7
8
func pdfViewControllerDidDismiss(_ pdfController: PSPDFViewController) {
	// 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")
}
Copy
1
2
3
4
5
6
7
8
- (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 PSPDFConfiguration, as seen below:

Copy
1
2
3
4
5
6
7
8
let configuration = PSPDFConfiguration { builder in
	// Restore the settings from the user defaults.
	let defaults = UserDefaults.standard
	builder.pageTransition = PSPDFPageTransition(rawValue: UInt(defaults.integer(forKey: "pageTransition")))!
	builder.pageMode = PSPDFPageMode(rawValue: UInt(defaults.integer(forKey: "pageMode")))!
	builder.scrollDirection = PSPDFScrollDirection(rawValue: UInt(defaults.integer(forKey: "scrollDirection")))!
	builder.spreadFitting = PSPDFConfigurationSpreadFitting(rawValue: defaults.integer(forKey: "spreadFitting"))!
}
Copy
1
2
3
4
5
6
7
8
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, please take a look at PersistSettingsOptionsExample.swift from the Catalog app.