0

I am trying to add a mask view to my front view in case when my rear view appears and I have written the following code for it -

func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {

     var maskView = UIView(frame: self.view.bounds)
      maskView.backgroundColor = UIColor.grayColor()
       maskView.alpha = 0.5
        maskView.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
      maskView.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
        if revealController.frontViewPosition == FrontViewPosition.Right
        {
          maskView.removeFromSuperview()//this block is called but mask view is not being removed.
          //maskView.hidden = true
          print("asdvf")

        }

        else if revealController.frontViewPosition == FrontViewPosition.Left
        {
            self.view.addSubview(maskView)

        }


    }

My mask view is added to the super view but is not removed from the super view despite the removal block called. Why so?

G.Abhisek
  • 1,034
  • 11
  • 44

1 Answers1

0
func revealController(_ revealController: SWRevealViewController!, didMoveTo position: FrontViewPosition) {
    if(position == FrontViewPosition.right) {

        let maskView = UIView(frame: self.view.frame)
        maskView.backgroundColor = UIColor.clear
        maskView.translatesAutoresizingMaskIntoConstraints = false
        let tap = UITapGestureRecognizer(target: revealController, action: #selector(SWRevealViewController.revealToggle(_:)))
        maskView.addGestureRecognizer(tap)
        maskView.addGestureRecognizer(revealController.panGestureRecognizer())
        maskView.tag = 1000
        revealController.frontViewController.view.addSubview(maskView)
        maskView.sizeToFit()
    } else {
          revealController.frontViewController.view.viewWithTag(1000)?.removeFromSuperview()
    }
}
Muhammad Noman
  • 1,566
  • 1
  • 15
  • 21