Transparent ViewController to See Parent Below?

后端 未结 9 843
自闭症患者
自闭症患者 2021-02-01 18:59

I would like to modally add a view controller with a transparent background, so the parent view controller beneath can be seen. (This is in an app for iPhone, not for iPad.)

9条回答
  •  梦如初夏
    2021-02-01 19:35

    For completeness and having it up-to-date, I am also adding the solution for Swift:

    either

    viewController.modalPresentationStyle = .CurrentContext 
    

    being - A presentation style where the content is displayed over only the presenting view controller’s content.

    or

    viewController.modalPresentationStyle = .OverCurrentContext
    

    being - A presentation style where the content is displayed over only the parent view controller’s content. The views beneath the presented content are not removed from the view hierarchy when the presentation finishes. So if the presented view controller does not fill the screen with opaque content, the underlying content shows through.

    Depending on the requirements and circumstances for the presentation.

提交回复
热议问题