我关注了AppCoda.com的补充工具栏菜单教程,我遇到了问题。我想在用户进入菜单时禁用用户交互。现在,尽管在菜单中,用户仍然能够与主屏幕进行交互。
链接到问题的屏幕截图: http://i.imgur.com/1gld2bY.gifv
答案 0 :(得分:2)
将此代码放在TableViewController中,即菜单项控制器。基本上这是位于主视图后面的视图控制器。
这也会使您的主视图变暗,如果您不想这样,则将alpha分量设置为0.
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()
}
答案 1 :(得分:0)
如果您使用 SWRevealViewController 作为侧边栏。使用以下代码
func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {
let tagId = 4207868622
if revealController.frontViewPosition == FrontViewPosition.Right {
let lock = self.view.viewWithTag(tagId)
UIView.animateWithDuration(0.25, animations: {
lock?.alpha = 0
}, completion: {(finished: Bool) in
lock?.removeFromSuperview()
}
)
lock?.removeFromSuperview()
} else if revealController.frontViewPosition == FrontViewPosition.Left {
let lock = UIView(frame: self.view.bounds)
lock.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
lock.tag = tagId
lock.alpha = 0
lock.backgroundColor = UIColor.blackColor()
lock.addGestureRecognizer(UITapGestureRecognizer(target: self.revealViewController(), action: "revealToggle:"))
self.view.addSubview(lock)
UIView.animateWithDuration(0.75, animations: {
lock.alpha = 0.333
}
)
}
}
注意:不要忘记在视图控制器中添加self.revealViewController().delegate = self
,否则不会调用代理