Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS- darken front view when rear view open using SWRevealViewController

I am trying to darken the front view when I reveal the rear view. is there any way to do this?

swift please (I'm not very experienced with objc.. I know, I know- no need to preach..)

Thanks

like image 709
Shlomo Koppel Avatar asked Jan 05 '23 09:01

Shlomo Koppel


1 Answers

In your MenuVC (the table View controller that lies behind and acts as a side menu). Add the following.

let darkView = UIView()

override func viewWillAppear(_ animated: Bool) {

    darkView.addGestureRecognizer(revealViewController().tapGestureRecognizer())
    darkView.backgroundColor = UIColor.black.withAlphaComponent(0.7)
    darkView.frame = self.revealViewController().frontViewController.view.bounds
    self.revealViewController().frontViewController.view.addSubview(darkView)
}

override func viewWillDisappear(_ animated: Bool) {
    darkView.removeFromSuperview()
}
like image 154
Munib Avatar answered Jan 07 '23 21:01

Munib