Option 1:
viewController.isModalInPresentation = true

(Disabled interactive .pageSheet dismissal acts like this.)
- Since the iOS 13,
UIViewControllercontains a new property calledisModalInPresentationwhich must be set totrueto prevent the interactive dismissal. - It basically ignores events outside the view controller’s bounds. Bear that in mind if you are using not only the automatic style but also presentation styles like
.popoveretc. - This property is
falseby default.
From the official docs: If
true, UIKit ignores events outside the view controller’s bounds and prevents the interactive dismissal of the view controller while it is onscreen.
Option 2:
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
return false
}
- Since the iOS 13,
UIAdaptivePresentationControllerDelegatecontains a new method calledpresentationControllerShouldDismiss. - This method is called only if the presented view controller is not dismissed programmatically and its
isModalInPresentationproperty is set tofalse.
Tip: Don’t forget to assign
presentationController‘s delegate. But be aware, it is known that even just accessing thepresentationControllercan cause a memory leak.