MMDrawerController can't close drawer

2k Views Asked by At

I'm trying to use MMDrawerController in my application, but I can't get the side drawer to close with gestures on the center view. I've used MMDrawerController somewhere else in my app with great success, but can't figure out why its not working in this case.

The top-level View Controller is a UINavigationController, whose default view controller is the MasterViewController (source below). This class extends MMDrawerController and configures the view for what I want (center and right, close gestures, max width). The center view has a button that opens the drawer. Once the drawer is open I can't close it with gestures on the center view. I added a button to the drawer and it can close the drawer programmatically, but I need to be able to tab/pan on the center view.

class MasterViewController: MMDrawerController {

override func viewDidLoad() {
    let centerView = storyboard!.instantiateViewControllerWithIdentifier("CenterControllerName") as? CenterControllerType
    super.setCenterViewController(centerView, withCloseAnimation: false, completion: nil)
    let drawer = storyboard!.instantiateViewControllerWithIdentifier("Drawer") as? DrawerType
    super.rightDrawerViewController = drawer
    super.setMaximumRightDrawerWidth(200, animated: true, completion: nil)
    super.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView | MMCloseDrawerGestureMode.TapCenterView
}

}

The function to open the drawer:

@IBAction func drawerButtonPressed(sender: AnyObject) {
    drawer?.openDrawerSide(MMDrawerSide.Right, animated: true, completion: nil)
}
2

There are 2 best solutions below

3
On BEST ANSWER

I was able to work around this by placing a ContainerView as the only object in my view and then configuring the MMDrawerContainer from my ViewController. It doesn't seem like the right answer but everything looks and functions right from the user's perspective.

0
On

Ok so I run into the same issue, and I am almost sure that it comes from this:

guddrawing.png

Ok, the VC1 (with the star) is our application Home, the VC2 is the left drawer, and the VC3 is the DrawerController.

During a long time I tried to put gesture functions in the VC1 and VC2, but only opening in the VC1, and closing in the VC2 would work. The functions I used in VC1:

let rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("showDrawer:"))

rightSwipe.direction = .Right
view.addGestureRecognizer(rightSwipe)

...

  func showDrawer(sender: UISwipeGestureRecognizer) {
    if let m = mmdc {
      if !m.isLeftDrawerOpen() {
        m.toggleDrawerSide(MMDrawerSide.Left, animated: true, completion: nil)
      }
    }
  }

And the same one in VC2 but with the LeftSwipe and closeDrawer.

The solution is tu put both of these functions and gestures recognizer in the VC3 (DrawerController).

The problem is coming from the fact that your gestures are defined for a given VC, but when you open the drawer, it changes the current VC by a new one, and the previous VC is just displayed but can't be interactif with. By putting things in the parentVC of VC1/VC2 it solves the problem.