Is there any way we can detect when the drawer is closed by dragging the center container? I wish to perform certain actions everytime the drawer is closed..
Asked
Active
Viewed 1,649 times
4 Answers
2
You can use
-(void)setGestureCompletionBlock:(void(^)(MMDrawerController * drawerController, UIGestureRecognizer * gesture))gestureCompletionBlock;
to set a callback block to be notified when a gesture is completed. In this block, query the drawerController to know what is currently open.
/**
Sets a callback to be called when a gesture has been completed.
This block is called when a gesture action has been completed. You can query the `openSide` of the `drawerController` to determine what the new state of the drawer is.
@param gestureCompletionBlock A block object to be called that allows the implementer be notified when a gesture action has been completed.
*/

Quentin Hayot
- 7,786
- 6
- 45
- 62
-
in my App Delegate? Or in any View Controller that I am using the Drawer in? – genaks Sep 11 '15 at 08:35
-
1Every time you will call this method, the callback will be replaced. So AppDelegate sounds good ;) – Quentin Hayot Sep 11 '15 at 08:37
-
Any idea what the Swift version would be? – genaks Sep 11 '15 at 08:39
-
I'm not familiar with Swift :( – Quentin Hayot Sep 11 '15 at 08:42
-
Ok.. Thanks for your help :) – genaks Sep 11 '15 at 08:47
-
Can you explain please how can I use this in the App delegate? – Ne AS Jul 03 '17 at 15:41
2
I think we can use following helper methods to detect MMDrawerController state.
For Objective-C
- (BOOL)isLeftOpen {
return (self.mm_drawerController.openSide == MMDrawerSideLeft);
}
- (BOOL)isRightOpen {
return (self.mm_drawerController.openSide == MMDrawerSideRight);
}
For Swift-3.x
func isLeftOpen() -> Bool {
return mm_drawerController.openSide == .left
}
func isRightOpen() -> Bool {
return mm_drawerController.openSide == .right
}.
Source: https://github.com/mutualmobile/MMDrawerController/issues/337

Aamir
- 16,329
- 10
- 59
- 65
0
Using Quentin's answer you can check for the drawer width on gesture completion as
[self setGestureCompletionBlock:^(MMDrawerController *drawerController, UIGestureRecognizer *gesture) {
if (drawerController.visibleLeftDrawerWidth == 0.0f) {
// "perform certain actions"
}
}];

Francisco Amado
- 80
- 1
- 7
0
You can get a callback whenever the drawer will be open and closed.
drawerController?.setDrawerVisualStateBlock({ (drawer, drawerSide, percentVisible) in
print(percentVisible)
if percentVisible > 0 && self.blackView.superview == nil {
//drawer opened
}
if percentVisible == 0 {
//drawer closed
}
})
Note: percentVisible will be 0 when drawer will be closed and 1 when the drawer will be opened.

Garima Saini
- 173
- 8