Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New iOS 13 Modal Presentation: Presenting Controller Doesn't Move Down

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!

like image 954
CentrumGuy Avatar asked Oct 07 '19 22:10

CentrumGuy


People also ask

How do I push navigation controller?

To push UINavigationController , first create a subclass of UIViewController , which will be a wrapper-/container- class for your UINavigationController and its content. This is a much more comprehensive answer which addresses the need to support hierarchical navigation controllers without modal presentation.

How do you dismiss the presenting view controller?

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.


1 Answers

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!

like image 198
CentrumGuy Avatar answered Sep 19 '22 13:09

CentrumGuy