2

有什么方法可以通过拖动中心容器来检测抽屉何时关闭?我希望每次关闭抽屉时执行某些操作..

4

4 回答 4

2

我认为我们可以使用以下辅助方法来检测 MMDrawerController 状态。

对于 Objective-C

- (BOOL)isLeftOpen {
    return (self.mm_drawerController.openSide == MMDrawerSideLeft);
}

- (BOOL)isRightOpen {
    return (self.mm_drawerController.openSide == MMDrawerSideRight);
}

对于 Swift-3.x

func isLeftOpen() -> Bool {
    return mm_drawerController.openSide == .left
}

func isRightOpen() -> Bool {
    return mm_drawerController.openSide == .right
}. 

来源: https ://github.com/mutualmobile/MMDrawerController/issues/337

于 2017-06-12T07:34:29.823 回答
2

您可以使用

-(void)setGestureCompletionBlock:(void(^)(MMDrawerController * drawerController, UIGestureRecognizer * gesture))gestureCompletionBlock;

设置手势完成时通知的回调块。在此块中,查询抽屉控制器以了解当前打开的内容。

/**
 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.
 */
于 2015-09-11T08:31:16.227 回答
0

使用 Quentin 的回答,您可以在手势完成时检查抽屉宽度

    [self setGestureCompletionBlock:^(MMDrawerController *drawerController, UIGestureRecognizer *gesture) {
    if (drawerController.visibleLeftDrawerWidth == 0.0f) {
        // "perform certain actions"
    }
}];
于 2015-12-07T12:05:48.280 回答
0

每当抽屉打开和关闭时,您都可以获得回调。

drawerController?.setDrawerVisualStateBlock({ (drawer, drawerSide, percentVisible) in
                print(percentVisible)
                if percentVisible > 0 && self.blackView.superview == nil {
                    //drawer opened
                                }
                                if percentVisible == 0 {
                                    //drawer closed
                                }
            })

注意:当抽屉关闭时,percentVisible 为 0,抽屉打开时为 1。

于 2017-07-18T10:57:43.157 回答