Apple changed multiple UI styles in iOS 13. One of them is the new way to present a detail view controller. The new presentation style will be enabled by default in iOS 13 and provides some new interactions.
The new presentation style can be helpful for your users, allowing them to always close the detail flow without pressing multiple times on the back button. Closing a detail page with iOS 13 is possible with a simple ‘pull-to-dismiss‘ gesture.
Another improvement that the new presentation style provides, is that the user better understands where in the app he is. The view controller that opened the detail view controller, is always visible behind the screen. When the user uses the ‘pull-to-dismiss‘ gesture, all view controllers in the detail flow will be closed and deinit.
By default, all detail pages that are presented, will use the new presentation style for iOS 13. This can be changed to the iOS 12 presentation style, which is named fullScreen.
Present ViewController in full screen
When developing Swift code for iOS 12 or below, your code may look something like this:
let detailVC = DetailViewController() present(detailVC, animated: true)
Above code will init a DetailViewController and present the DetailViewController. In iOS 12, the DetailViewController will be presented full screen. Using iOS 13, the DetailViewController will be presented with the new presentation style, which is named ‘Automatic’. To prevent this, the presentation style can be changed.
To present the DetailViewController full screen, the modalPresentationStyle property of a view controller must be set to .fullScreen before it will be presented. The code below shows how this works with the previous code example.
let detailVC = DetailViewController() detailVC.modalPresentationStyle = .fullScreen present(detailVC, animated: true)
Above example sets the modelPresentationStyle to .fullScreen for DetailViewController. Because of this, the view controller will also be presented in full screen on iOS 13.
Present NavigationController in full screen
You must set the modalPresentationStyle property of the view controller that will be presented. If you want to present a NavigationController which contains a view controller, the NavigationController that will be presented must have set the property modalPresentationStyle, instead of the view controller that will be visible.
The code example below makes it clearer how to deal with the presentation style when presenting a NavigationController.
let detailVC = DetailViewController() let navigationController = UINavigationController(rootViewController: detailVC) navigationController.modalPresentationStyle = .fullScreen present(navigationController, animated: true)
🚀 Like this article? Follow me on Twitter for more iOS related news!