16
votes

I have a weird behavior when presenting UIViewControllers modally in iOS 13. The new presentation style that I've seen all across iOS 13 looks like this:

The presenting view controller appears behind the presented view controller. It is also shifted down to mimic a "stack"

The presenting view controller appears behind the presented view controller. It is also shifted down to mimic a "stack"

Meanwhile, when presenting view controllers through my app, I keep getting this effect:

The presenting view controller doesn't move at all when presenting a new view controller

The presenting view controller doesn't move at all when presenting a new view controller

I use this code to present this view controller:

let controller = storyboard?.instantiateViewController(withIdentifier: "tutorial") as! TutorialController
controller.modalPresentationStyle = .pageSheet
controller.modalTransitionStyle = .coverVertical
present(controller, animated: true, completion: nil)

Here is my question: I'm wondering why this is happening and if there is a way to present view controllers in the normal iOS 13 style (with the presenting view controller moving back).

Thanks in advance!

6
As a test, try commenting out the controller.modalTransitionStyle = .coverVertical and even the controller.modalPresentationStyle = .pageSheet (though the presentation style would be needed if this code is also run on an iPad).rmaddy
I commented it out but it doesn’t change anything :(CentrumGuy

6 Answers

5
votes

Turns out the problem was my view controller hierarchy. I was able to fix it by making the presenting view controller the root view controller of my app. First I set the background controller as the root view controller by calling

window.rootViewController = self

and then using my previous code

let controller = storyboard?.instantiateViewController(withIdentifier: "tutorial") as! TutorialController
controller.modalPresentationStyle = .pageSheet
controller.modalTransitionStyle = .coverVertical
present(controller, animated: true, completion: nil)

I presented the view controller. Thanks to everyone who tried to help!

1
votes

I think the issue can be resolved by using vc.modalPresentationStyle = .fullScreen if there is not UINavigationController , otherwise you can use these codes as follows:

let navigationController = UINavigationController(rootViewController: vc) 
navigationController.modalPresentationStyle = .fullScreen 
present(vc, animated: true)

because With iOS 13 this is a new feature that Apple has changed the default presentation style of View Controllers to a modal sheet from fullscreen in iOS 12

1
votes

iOS13: Let's say you have 3 view controllers: FirstVC, SecondVC, ThirdVC

FirstVC presents SecondVC with the below code:

let secondVC = SecondVC()
secondVC.modalPresentationStyle = .fullScreen
firstVC.present(secondVC, animated: true, completion: nil)

SecondVC presents ThirdVC with the below code:

let thirdVC = ThirdVC()
secondVC.present(thirdVC, animated: true, completion: nil)

Changing secondVC's modalPresentationStyle to .currentContext solves the problem.

0
votes

We can change it in the Inspector Tool Bar. To Achieve it: head over to the fifth section of Inspector Tollbar then change the Presentation field to Full Screen.

0
votes

Programmatically:

let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen //or .overFullScreen for transparency
self.present(vc, animated: true, completion: nil)

From storyboard:

enter image description here

That's it. No need to play with root controller or window at all.

For reference, visit this article.

-1
votes

This should be the only property you need to set

presentedViewController.modalPresentationStyle = .automatic

Detailed in https://developer.apple.com/videos/play/wwdc2019/224/