Transparent ViewController to See Parent Below?

后端 未结 9 845
自闭症患者
自闭症患者 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:47

    @Josh Kahane set the view controller that will present the transparent view controller with this code at the -ViewDidLoad and be sure to set the alpha channel of the UIViewController View to be lower then 1.

    Code:

    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    
    0 讨论(0)
  • 2021-02-01 19:48

    When you modally present a view controller the , it goes on the stack which in turn hides the view controller below it. So all you can do is to present a transparent view with animation similar to modally presenting a view controller.

    0 讨论(0)
  • 2021-02-01 19:50

    Swift 3 -

    Try vc.modalPresentationStyle = .overFullScreen

    let vc = self.storyboard!.instantiateViewControllerWithIdentifier("ExampleViewController") as! ExampleViewController
    vc.view.backgroundColor = UIColor.clearColor()
    vc.modalPresentationStyle = .overFullScreen
    self.presentViewController(vc, animated: true, completion: nil)
    
    0 讨论(0)
提交回复
热议问题