Views not modal anymore in new iOS 13 and 14

Hello,

I have a Button which popups a modal form:

MyView2.ViewController.setModalPresentationStyle(UIModalPresentationFormSheet);
MyView2.ViewController.setPreferredContentSize(MyView2.View.frame.size);
MyView1.ViewController.presentViewController(MyView2.ViewController, true, MyView2Init);

In earlier versions of IOS this form was modal, meaning that it would not close when clicking on the main window (here MyView1) at the background.

With current IOS 14 when clicking the background, the form disappears and leaves it in an undesired state.

How can I get the modal behavior back?

Best Regards and Thanks in advance!

This is an iOS specific issue. Apple has changed the behavior of modal presented controllers. I think you have 2 options to fix the issue:

  1.  Use a full-screen view controller
    
  2.  Use the isModalInPresentation property at viewcontroller level.
    

When reading the documentation, it states that it blocks the view from getting swiped away.

When using the second approach, you can use the following code:

MyView2.ViewController.setModalInPresentation(true);