1

I'm using MMdrawerController for an Objective-C project and it works well using this hamburger icon on the drawer to trigger it to open and close. When the drawer is closed, it rests at the edge of the right side of the screen until it's opened again by clicking the hamburger icon. Now, I would like to make the whole drawer clickable instead of just the icon, so that the drawer opens wherever I click on it.

Is there a straight forward way to do this, because the only thing I really can think of is creating an invisible button where the drawer is and make that trigger the open/close code.

The code for triggering the drawer looks like this:

[self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];

EDIT I tried using both touchesBegan as well as UITapGestureRecognizer like this:

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSLog(@"PRESS");
}

and

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
[self.view addGestureRecognizer:recognizer];

-(void)tapped {
    NSLog(@"TAPPED");
}

They only get triggered when the drawer has already been opened and I press somewhere in the viewController, but it doesn't trigger when the drawer is resting to the side of the screen (when it is closed).

  • You can add a TapGestureRecognizer to your drawerController's view – CZ54 Mar 27 '20 at 07:50
  • I did add the `touchesEnded` delegate to the `class` that the `drawer` currently contain, but it only triggered on touches when the `drawer` had already been opened, not when it rests at the right side of the screen. What am I missing? – screenMonkey MonkeyMan Mar 27 '20 at 08:26
  • I also tried using `UITapGestureRecognizer` but with the same results: it works when the `drawer` has been opened already, but not when it's resting at the side. – screenMonkey MonkeyMan Mar 27 '20 at 08:44

0 Answers0