When presenting a view controller modally, we can set the modalPresentationStyle
to .formSheet
:
In a horizontally regular environment, the view controller is sized so that its content area is smaller than the screen size and a dimming view is placed underneath the content...
In a horizontally compact environment, this option behaves the same as UIModalPresentationStyle.fullScreen.
I would like my modally presented view controller to update its layout based on whether it is being presented in this reduced-width form style, or as a full screen presentation. But The modal's horizontal size class is always compact
, even when full screen on an iPad Pro in landscape.
The horizontal size class of the presenting view controller can tell me what I need to know (as Apple's docs mention above). But that means observing changes in traitCollection in every view controller than can present my modal, just so they pass them on to the modal view controller.
Is there some way for the modal view controller itself to know which style it is using, and be alerted when it changes so it can respond?