Transparent background for modally presented viewcontroller

前端 未结 5 1371
再見小時候
再見小時候 2020-11-29 03:04

I am using Parse & ParseUI. I want my PFLoginViewController subclass to have a transparent background. In the future, I want to lay a blurred view over the background.

5条回答
  •  广开言路
    2020-11-29 03:52

    Part of the solution is hidden in the question. You need three lines to make the background transparent, viz. isOpaque = false backgroundColor = .clear & set the modalPresentationStyle

    Here's the full solution. In the calling View Controller, call this function:

    func presentModal() {
        let modalController = ModalViewController()
        modalViewController.modalPresentationStyle = .overCurrentContext
        present(modalViewController, animated: true, completion: nil)
    }
    

    And in ModalViewController's viewDidLoad():

    override func viewDidLoad() {
        super.viewDidLoad()
    
        view.isOpaque = false
        view.backgroundColor = .clear // try other colors, say: .white or black with Alpha etc.
    }
    

提交回复
热议问题