我遵循AppCoda.com的邊欄菜單教程,我遇到了問題。我想在用戶進入菜單時禁用用戶交互。目前,用戶仍然能夠與主屏幕進行交互,儘管它在菜單中。如何使用SWRevealViewController禁用邊欄菜單中的交互
鏈接到問題的截圖: http://i.imgur.com/1gld2bY.gifv
我遵循AppCoda.com的邊欄菜單教程,我遇到了問題。我想在用戶進入菜單時禁用用戶交互。目前,用戶仍然能夠與主屏幕進行交互,儘管它在菜單中。如何使用SWRevealViewController禁用邊欄菜單中的交互
鏈接到問題的截圖: http://i.imgur.com/1gld2bY.gifv
將這個代碼在你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()
}
如果您正在使用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
,否則代表將不會被調用
我有點困惑,我應該把這個 –
也添加'self.revealViewController()。委託= self'給我一個錯誤。它說我不能將我的視圖控制器分配給SWRevealViewControllerDelegate類型! –
在你的viewDidLoad方法中添加self.revealViewController()。delegate = self。上面的代碼在你班上的任何地方。這就像方法 –
當主視圖控制器進入到一邊,你可以添加一個UIView在那裏,這樣它不會影響任何東西。如果你想讓它變暗,你也可以做到這一點。你在使用SWRevealViewController嗎? – Munib
是的,我認爲這可能是我想要做的最好的選擇。 –
如果你想做類似的事情,讓我發佈我的代碼。 – Munib