How to present a semi-transparent (half-cut) viewcontroller in iOS?

后端 未结 5 2321
既然无缘
既然无缘 2020-12-28 22:28

I use the following code to present a viewcontroller. My problem is: After the animation completes, the transparent main background becomes opaque black.

How can I f

5条回答
  •  一向
    一向 (楼主)
    2020-12-28 22:59

    This is a fairly simple problem to solve. Rather than creating a custom view transition, you just need to set the modalPresentationStyle for the view controller being presented. Also, you should set the background color (and alpha value) for the view controller being presented, in the storyboard / via code.

    CustomViewController: UIViewController {
        override func viewDidLoad() {
          super.viewDidLoad()
          view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.6)
        }
    }
    

    In the IBAction component of presenting view controller -

    let vc = storyboard?.instantiateViewControllerWithIdentifier("customViewController") as! CustomViewController
    vc.modalPresentationStyle = UIModalPresentationStyle.Custom
    presentViewController(vc, animated: true, completion: nil)
    

提交回复
热议问题