mutualmobile / MMDrawerController

A lightweight, easy to use, Side Drawer Navigation Controller
MIT License
6.76k stars 1.38k forks source link

How to disable drawer open and close #518

Open Mahesh160393 opened 5 years ago

Mahesh160393 commented 5 years ago

Is it possible to disable open/close by swiping?

I want to disable swipe. when we click on UIBarButtonItem then it will open.

Thank You in advance

Mahesh160393 commented 5 years ago

@danmurrelljr help me

maniarali commented 5 years ago

My solution to this problem is creating extension in your UIViewController like this:

extension UIViewController {

    func enableSideMenu() {
        if self.mm_drawerController != nil {
            self.mm_drawerController.openDrawerGestureModeMask = .bezelPanningCenterView
        }
    }

    func disableSideMenu() {
        if self.mm_drawerController != nil {
            self.mm_drawerController.openDrawerGestureModeMask = .init(rawValue: 0)
        }
    }

}

After this in whatever view controller you want to disable your side menu call

self.disableSideMenu()

and to re-enable

self.enableSideMenu()

For Example:-

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.disableSideMenu()
}
override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        self.enableSideMenu()
}

I hope this is helpful