【问题标题】:Mask view not removed from super view in case of SWRevealViewController在 SWRevealViewController 的情况下,掩码视图未从超级视图中删除
【发布时间】:2016-02-01 09:52:54
【问题描述】:

我正在尝试在我的前视图中添加一个遮罩视图,以防我的后视图出现并且我已经为它编写了以下代码 -

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)

        }


    }

我的蒙版视图已添加到超级视图中,但尽管调用了删除块,但并未从超级视图中删除。为什么会这样?

【问题讨论】:

    标签: ios swift uiview swrevealviewcontroller


    【解决方案1】:
    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()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多