简体   繁体   中英

How to know when a view controller is presented using a 'form sheet' modal presentation style

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?

至少了解应用程序大小类别的一种粗略方法:

UIApplication.shared.delegate?.window??.rootViewController?.traitCollection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM