Modally Presented View Controllers


There are a lot of view controllers presented modally in PSPDFKit. You have the ability to customize the behavior and the look of all the view controllers. In this article you will learn how to achieve the exact behavior and look you desire.

Hide the close button

We automatically add a close button to all modally presented view controllers. If you don't want that button or if you want to customize this behavior, you can set

Hide the close button for PSPDFViewController

To hide the close button on a modally presented PSPDFViewController, set closeBarButtonItem of the navigationItem to nil.

Hide the close button on a view controller presented from PSPDFViewController

Override presentViewController:options:animated:sender:completion: in your PSPDFViewController subclass and edit the options dictionary to set PSPDFPresentationCloseButtonKey to false.

In the following code snippet, we hide the close button only for presented instances of PSPDFNoteAnnotationViewController. Be aware that there is no other way to dismiss the view controller, if you do this, and don't add your custom close button.

Copy
1
2
3
4
5
6
7
override func present(_ controller: UIViewController, options: [String : Any]? = nil, animated: Bool, sender: Any?, completion: (() -> Void)? = nil) -> Bool {
    var customOptions = options
    if controller is PSPDFNoteAnnotationViewController {
        customOptions?[PSPDFPresentationCloseButtonKey] = false
    }
    return super.present(controller, options: customOptions, animated: animated, sender: sender, completion: completion)
}
Copy
1
2
3
4
5
6
7
- (BOOL)presentViewController:(UIViewController *)controller options:(nullable NSDictionary<NSString *, id> *)options animated:(BOOL)animated sender:(nullable id)sender completion:(void (^)(void))completion {
    NSMutableDictionary<NSString *, id> *customOptions = options.mutableCopy;
    if ([controller isKindOfClass:PSPDFNoteAnnotationViewController.class]) {
        customOptions[PSPDFPresentationCloseButtonKey] = @NO;
    }
    return [super presentViewController:controller options:customOptions animated:animated sender:sender completion:completion];
}
Was this page helpful? We're happy to answer any questions.