MMDrawerController.m 重写手势识别区域
-(BOOL)isPointContainedWithinCenterViewContentRect:(CGPoint)point{
CGRect centerViewContentRect = CGRectMake(0, 0, 50, self.centerContainerView.frame.size.height);
//修改后的意思是把触发打开抽屉手势识别放在屏幕左侧宽50,高为屏幕高度的rect中
centerViewContentRect = CGRectIntersection(centerViewContentRect,self.childControllerContainerView.bounds);
return (CGRectContainsPoint(centerViewContentRect, point) &&
[self isPointContainedWithinNavigationRect:point] == NO);
}
如果想要只在一个视图控制器里显示抽屉效果修改如下
//1.修改框架里面的方法
-(MMDrawerController*)mm_drawerController{
// if([self.parentViewController isKindOfClass:[MMDrawerController class]]){
// return (MMDrawerController*)self.parentViewController;
// }
// else if([self.parentViewController isKindOfClass:[UINavigationController class]] &&
// [self.parentViewController.parentViewController isKindOfClass:[MMDrawerController class]]){
// return (MMDrawerController*)[self.parentViewController parentViewController];
// }
// else{
// return nil;
// }
UIViewController *parentCtrl = self.parentViewController;
while (parentCtrl) {
if ([parentCtrl isKindOfClass:[MMDrawerController class]]) {
return (MMDrawerController *)parentCtrl;
}
parentCtrl = parentCtrl.parentViewController;
}
return nil;
}
//2.在想要开启滑动的视图的方法里面这样写
//试图将要显示时打开开启和关闭手势
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.mm_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
}
//视图将要消失时关闭打开和关闭手势
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
[self.mm_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeNone];
}
网友评论