Augusto
Augusto

Reputation: 4243

How to make a transparent background of Popup ViewController?

I've a ViewController as popup to pick a date on UIDatePicker. But when, this popup opens, the background is covered by new background color. I tried choose a opacity of color, but this not works. I use a UILabel to handler click and open a new ViewController.

override func viewDidLoad() {
        super.viewDidLoad()

        let tapDateSelectExpiration = UITapGestureRecognizer(target: self, action: #selector(handleSelectDateExpiration))
        let tapDateSelectValidity = UITapGestureRecognizer(target: self, action: #selector(handleSelectDateValidity))
        let tapDateSelectOrder = UITapGestureRecognizer(target: self, action: #selector(handleSelectDateOrder))

        lblDataPedido.isUserInteractionEnabled = true
        lblDataValidade.isUserInteractionEnabled = true
        lblDataExpiracao.isUserInteractionEnabled = true

        lblDataPedido.addGestureRecognizer(tapDateSelectOrder)
        lblDataValidade.addGestureRecognizer(tapDateSelectValidity)
        lblDataExpiracao.addGestureRecognizer(tapDateSelectExpiration)
    }

@objc func handleSelectDateExpiration(_ sender : UILabel) {
        print("handleSelectDateExpiration")
        var vcSelectDate = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerSelectDate") as! ViewControllerSelectDate
        vcSelectDate.typeDate = "DateExpiration"
        self.present(vcSelectDate,animated: true,completion: nil)
    }

// Other funcs as above.

MainLayout:

MainLayout

DatePicker layout with backgroud not transparent:

DatePicker layout with backgroud not transparent

Storyboard:

enter image description here

Upvotes: 1

Views: 1938

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100541

You can try

let vc = self.storyboard?.instantiateViewController(withIdentifier: "dateView") as! dateViewController

vc.delegate = self

vc.providesPresentationContextTransitionStyle = true;

vc.definesPresentationContext = true;

vc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext

self.present(vc, animated: false, completion: nil)

and select transparent background like this

enter image description here

or in IB

enter image description here

Upvotes: 3

Related Questions