2

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..

genaks
  • 757
  • 2
  • 10
  • 24

4 Answers4

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
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"
    }
}];
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