我正在尝试在我的前视图中添加一个蒙版视图,以防我的后视图出现并且我已经为它编写了以下代码 -
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)
}
}
我的掩码视图被添加到超级视图中,但是除非调用了删除块,否则不会从超级视图中删除。为什么这样?
答案 0 :(得分: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()
}
}