Hi,
I would like to disable the SideMenu pan gesture recognizer for particular view controllers.
Do yoy know a proper way to do that ?
Thanks !
@nahouto When you call menuAddPanGestureToPresent or menuAddScreenEdgePanGesturesToPresent to add the gestures, they return the recognizer(s) attached the the views. You simply need to keep a reference to those recognizers when they're setup so you can turn them off/on at the appropriate times, OR set them up only on view controllers that need them (and not in a navigation controller).
If you still want to set them up in a navigation controller, then create a navigation controller subclass, have it add those gestures and keep references to them, and then toggle them off/on based on the navigation controller it's displaying.
If you still want to set them up in a navigation controller, then create a navigation controller subclass, have it add those gestures and keep references to them, and then toggle them off/on based on the navigation controller it's displaying.
Great ! Here is my implementation :
class MyNavigationController: UINavigationController {
// pan gestures recognizers
var panGesture = UIPanGestureRecognizer()
var edgeGesture = [UIScreenEdgePanGestureRecognizer]()
override func viewDidLoad() {
super.viewDidLoad()
// add gesture recognizer
panGesture = SideMenuManager.menuAddPanGestureToPresent(toView: self.navigationBar)
edgeGesture = SideMenuManager.menuAddScreenEdgePanGesturesToPresent(toView: self.view)
}
// disable side menu
func disableSideMenu() {
panGesture.enabled = false
edgeGesture.forEach{$0.enabled = false}
}
// enable side menu
func enableSideMenu() {
panGesture.enabled = true
edgeGesture.forEach{$0.enabled = true}
}
}
Not sure about your scenario, but in my case when user logs out and reach on login screen i wanted to disable gesture from left to right.
At th etime user clicks on logout i set below property to 0.0 and that's it.
SideMenuManager.default.menuWidth = 0.0
Now again reset it to 85% after user re-login.
You can Simple Do this
Replace
SideMenuManager.default.menuAddScreenEdgePanGesturesToPresent(toView: (self.navigationController?.view)!)
with
SideMenuManager.default.menuAddScreenEdgePanGesturesToPresent(toView: (self.view)!)
Now sidemenu will only open in current View where you have setup the sidemenu.
Most helpful comment
Great ! Here is my implementation :