Fix: Disable Interactive Dismissal of Presented View Controller in iOS 13+

Fix: Disable Interactive Dismissal of Presented View Controller in iOS 13+

Written by

in

Quick answer: Set viewController.isModalInPresentation = true on the presented view controller to disable the pull-to-dismiss gesture while keeping the pageSheet or formSheet style. Alternatively, implement presentationControllerShouldDismiss in a UIAdaptivePresentationControllerDelegate and return false.

Why this happens

iOS 13 changed the default behavior of .pageSheet and .formSheet presentation styles. These modals now support an interactive dismissal gesture: users can drag the presented view controller down to dismiss it. While this matches the system’s new card-style presentation, many apps need to prevent accidental dismissal — for example, when a sheet contains a form that must be explicitly saved or cancelled.

The interactive dismissal is enabled by default because isModalInPresentation defaults to false. When false, UIKit allows touches outside the presented view’s bounds to initiate the drag-to-dismiss interaction. Setting the property to true tells UIKit to ignore those outside events and block the gesture.

How to fix it

1. Set isModalInPresentation on the presented view controller (recommended)

This is the simplest, most direct fix. Apply it before presenting the view controller.

let detailVC = DetailViewController()
detailVC.modalPresentationStyle = .pageSheet
if #available(iOS 13.0, *) {
    detailVC.isModalInPresentation = true
}
present(detailVC, animated: true)

Why this works: The property is checked by the presentation controller when the sheet is on screen. When true, the system treats the modal as “modal in presentation” — it blocks interactive dismissal and also ignores taps outside the view controller’s bounds.

Note: This also prevents taps outside the sheet from passing through to the presenting view. If you need outside taps to work while still blocking the drag gesture, use the delegate approach below.

2. Implement UIAdaptivePresentationControllerDelegate

Use this when you need conditional logic (e.g., block dismissal only when a form is dirty) or when you want to keep outside-tap passthrough.

class DetailViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // The presenting view controller (or self) can be the delegate
        presentationController?.delegate = self
    }
}

extension DetailViewController: UIAdaptivePresentationControllerDelegate {
    func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
        // Return false to block interactive dismissal
        return !hasUnsavedChanges
    }

    // Optional: run code when the user *tries* to dismiss interactively
    func presentationControllerDidAttemptToDismiss(_ presentationController: UIPresentationController) {
        // Show an alert, highlight unsaved fields, etc.
    }
}

Important: The delegate method presentationControllerShouldDismiss is only called when isModalInPresentation is false. If you set that property to true, the delegate method will not be invoked for interactive dismissal.

Memory leak warning: Accessing presentationController on a view controller that isn’t currently presented can create a retain cycle in some iOS versions. Assign the delegate in viewDidLoad or viewWillAppear only after the view controller is already in the presentation hierarchy, or set it from the presenting side:

swift
let detailVC = DetailViewController()
detailVC.modalPresentationStyle = .pageSheet
detailVC.presentationController?.delegate = self // presenting VC acts as delegate
present(detailVC, animated: true)

3. Use .fullScreen presentation style (alternative)

If you don’t need the card-style sheet appearance, switch to full-screen presentation. This restores the pre-iOS 13 behavior where modals cover the entire screen and have no interactive dismissal.

let vc = SomeViewController()
vc.modalPresentationStyle = .fullScreen
present(vc, animated: true)

In a storyboard, select the segue and choose Presentation → Full Screen.

Trade-off: You lose the compact sheet UI and the ability to see the presenting content behind the modal.

How to prevent it

  • Decide the dismissal policy early: if a screen must not be dismissed by gesture, set isModalInPresentation = true in the view controller’s initializer or viewDidLoad.
  • For forms, combine isModalInPresentation = true with a visible Cancel button that calls dismiss(animated: true) programmatically — programmatic dismissal always works.
  • When using the delegate, keep the presentationControllerShouldDismiss logic simple and fast; it runs on the main thread during the drag gesture.
  • Test on both iPhone and iPad: .formSheet on iPad behaves differently and may not need the same treatment.

FAQ

Does isModalInPresentation work on iOS 12 and earlier?

No. The property was introduced in iOS 13. Wrap it in an #available(iOS 13.0, *) check. On iOS 12, .pageSheet and .formSheet do not have interactive dismissal, so no action is needed.

Can I allow outside taps but still block the drag-to-dismiss gesture?

Yes. Use the UIAdaptivePresentationControllerDelegate approach with isModalInPresentation = false. The delegate’s presentationControllerShouldDismiss blocks the interactive drag, while taps outside the sheet still reach the presenting view controller.

Why does my delegate method never get called?

Check that isModalInPresentation is false on the presented view controller. If it’s true, the system blocks interactive dismissal before asking the delegate. Also verify the delegate is set on the presentation controller (not the view controller) and that the presenting view controller retains the delegate object.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.