使用抽屉MMDrawerController和系统手势interactivePopGestureRecognizer冲突的解决方法(转)

在使用抽屉菜单 MMDrawerController的过程中,发现经常遇到一个问题:
1.在不该出现侧滑的地方出现了侧滑;
2.侧滑后pushviewcontroller卡住;
排查了很久找到了问题,是navigationController中得interactivePopGestureRecognizer和MMDrawerController两者冲突导致的。
我们通常开启边缘返回手势的方法是 self.navigationController.interactivePopGestureRecognizer.delegate = self; 这个就相当于开启了一个手势:在屏幕最左侧向最右侧滑动时会popViewController。

//添加边缘返回手势  
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {  
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;  
}  

对于MMDrawerController我们如果开启了手势打开/关闭:

[drawerControlller setMaximumRightDrawerWidth:200.0];  
[drawerControlller setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];  
[drawerControlller setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];  
[[MMExampleDrawerVisualStateManager sharedManager] setLeftDrawerAnimationType:MMDrawerAnimationTypeSlideAndScale];  

两者如果都同时开启,频繁滑动侧滑菜单有时就会出现PushViewController没有响应的情况,
解决方法:
1.对于MMDrawderController:
在开启侧滑功能的viewcontroller.view消失的时候关闭侧滑功能,出现的时候再打开:

- (void) viewDidAppear:(BOOL)animated{  
    [super viewDidAppear:animated];  
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;  
    [[MPCDrawerControlller sharedDrawerController] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];  
}  
- (void)viewDidDisappear:(BOOL)animated  
{  
    [super viewDidDisappear:animated];  
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;  
    [[MPCDrawerControlller sharedDrawerController] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];  
}  

你可能感兴趣的:(使用抽屉MMDrawerController和系统手势interactivePopGestureRecognizer冲突的解决方法(转))