我想检测菜单何时关闭。我发现这个 SO 解决了问题。在接受的答案的评论中,他们说这种方法:
-(void)setGestureCompletionBlock:(void(^)(MMDrawerController * drawerController, UIGestureRecognizer * gesture))gestureCompletionBlock;
必须在App delegate
中才能在菜单关闭时收到通知。我把这个函数放在我的 App 委托中,在它的实现中我做了一个NSLog(@"menu closed");
但没有打印在我的控制台中,并且当我关闭菜单时这个函数没有被触发。
谁能解释我如何检测菜单已关闭?(根据给定的答案或如果您有另一个答案)
编辑:
在情节提要中,我有一个 UINavigationController 链接到一个 UIViewController,其类型为 MMDrawerController( myVCMMdrawerController
),然后我还有myCenterVC
,leftVC
和rightVC
. 在myVCMMdrawerController
viewDidLoad
这就是我所做的:
MyCenterVC * centerVC = [[self storyboard] instantiateViewControllerWithIdentifier:@"myCenterVC"];
centerVC.drawerController = self;
LeftVC * leftVC = [[self storyboard] instantiateViewControllerWithIdentifier:@"leftVC"];
leftVC.drawerController = self;
self.centerViewController = centerVC;
self.leftDrawerViewController = leftVC;
self.showsShadow = false;
//[self setMaximumLeftDrawerWidth:[UIScreen mainScreen].bounds.size.width animated: true completion: nil];
//enable gesture
self.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
self.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
[self closeDrawerAnimated:NO completion:nil];
在myCenterVC
我进行操作以在 IBActions 中显示菜单,如下所示:
[self.drawerController toggleDrawerSide:MMDrawerSideLeft animated:true completion:nil];