在 SWRevealViewController 的情况下,掩码视图未从超级视图中删除
Posted
技术标签:
【中文标题】在 SWRevealViewController 的情况下,掩码视图未从超级视图中删除【英文标题】:Mask view not removed from super view in case of 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)
我的蒙版视图已添加到超级视图中,但尽管调用了删除块,但并未从超级视图中删除。为什么会这样?
【问题讨论】:
【参考方案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()
【讨论】:
以上是关于在 SWRevealViewController 的情况下,掩码视图未从超级视图中删除的主要内容,如果未能解决你的问题,请参考以下文章
带有 SWRevealViewController 的 ios 滑动状态栏
在 secondviewcontroller UIBarbuttonItem 对于 swrevealviewcontroller 不可见?