I see UIHostingController hosting a SwiftUI view which is presented modally. The problem I see is it doesn't resize on autorotation if the modalPresentationStyle is set to overCurrentContext.
let promptHostingController = UIHostingController(rootView: promptView)
promptHostingController.isModalInPresentation = true
promptHostingController.overrideUserInterfaceStyle = .dark
promptHostingController.modalPresentationStyle = .overCurrentContext
self.present(promptHostingController, animated: animated)
Setting it to any other value such as overFullScreen solves the problem. Buy wanted to know why it fails to resize with overCurrentContext?
Nothing in the documentation of
overCurrentContextsays that the presented view would resize to fit the whole screen. It doesn't mention anything about the size of the presented view at all:The documentation also says:
This is exactly the case here - you did not write code that resizes the view when the screen is rotated, so the view "does not fill the screen" (let alone "opaque content") after the device is rotated.
The documentation of
overFullScreen, however, does say it will "cover" the whole screen.Note the different choice of words here - "cover" as opposed to just "over".
Anyway, if you want it to cover the view controller that
definesPresentationContext, you can add auto layout constraints to the view yourself.You should add the constraints after the hosting controller is presented, which is why I put
NSLayoutConstraint.activatein the completion handler ofpresent. Before that, the presented view is not yet in the view hierarchy yet.Also, use
intrinsicContentSizeas the sizing option. As its documentation says, you should use this when you layout the hosting view with AutoLayout.