When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it.
The block to execute after the view controller is dismissed. This block has no return value and takes no parameters.
viewController.isModalInPresentation = true
(Disabled interactive .pageSheet
dismissal acts like this.)
UIViewController
contains a new property called isModalInPresentation
which must be set to true
to prevent the interactive dismissal. .popover
etc. false
by 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.
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
return false
}
UIAdaptivePresentationControllerDelegate
contains a new method called presentationControllerShouldDismiss
.isModalInPresentation
property is set to false
.Tip: Don't forget to assign presentationController's delegate.
If you want the same behaviour as it's in previous iOS version (< iOS13) like model presentation in fullscreen, just set the presentation style of your destination view controller to UIModalPresentationStyle.fullScreen
let someViewController = \*VIEW CONTROLLER*\
someViewController.modalPresentationStyle = .fullScreen
And if you are using storyboard just select the segua and select Full Screen
form the Presentation
dropdown.
If you just want to disable the interactive dismissal and keep the new presentation style set UIViewController
property isModalInPresentation
to true
.
if #available(iOS 13.0, *) {
someViewController.isModalInPresentation = true // available in IOS13
}
The property isModalInPresentation
might help.
From the documentation:
When you set it to
true
, UIKit ignores events outside the view controller's bounds and prevents the interactive dismissal of the view controller while it is onscreen.
You can use it like this:
let controller = MyViewController()
controller.isModalInPresentation = true
self.present(controller, animated: true, completion: nil)
If you are using storyboards to layout your UI I have found the best way to disable this interactive dismissal when using a navigation controller is to change the presentation of the Navigation Controller in the attribute inspector from Automatic to Full Screen. All view controllers in your navigation stack will then be full screen and will not be able to be dismissed by the user.
Attribute Inspector showing presentation option for the navigation controller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With