码迷,mamicode.com
首页 > 其他好文 > 详细

MMDrawerController 使用遇到的问题及定制

时间:2016-05-11 13:06:25      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

MMDrawerController

1,
集成
UIViewController * leftDrawer = [[UIViewController alloc] init]; UIViewController * center = [[UIViewController alloc] init]; UIViewController * rightDrawer = [[UIViewController alloc] init]; MMDrawerController * drawerController = [[MMDrawerController alloc] initWithCenterViewController:center leftDrawerViewController:leftDrawer rightDrawerViewController:rightDrawer];

详细代码

 

    tabVC = [[TabBarController alloc]init];

    

    //左边页面框架

    LeftPage *leftController = [[LeftPage alloc] init];

    

    

    self.drawerController = [[MMDrawerController alloc]

                             initWithCenterViewController:tabVC

                             leftDrawerViewController:leftController

                             rightDrawerViewController:nil];

    [self.drawerController setShowsShadow:NO];

    [self.drawerController setRestorationIdentifier:@"MMDrawer"];

    [self.drawerController setMaximumLeftDrawerWidth:260.0];

    // self.drawerController.visibleLeftDrawerWidth = 260;

    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];

    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

    //侧滑推出风格

    [[MMExampleDrawerVisualStateManager sharedManager] setLeftDrawerAnimationType:1];

    

    [self.drawerController

     setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {

         MMDrawerControllerDrawerVisualStateBlock block;

         

         block = [[MMExampleDrawerVisualStateManager sharedManager]

                  drawerVisualStateBlockForDrawerSide:drawerSide];

         if(block){

             block(drawerController, drawerSide, percentVisible);

         }

     }];

    [self.window setRootViewController:self.drawerController];


重新定义主界面左上角按钮 事件

-(void)leftBtnPressed

{

   // [[(AppDelegate *)[[UIApplication sharedApplication] delegate] menuController] showLeftController:YES];

    [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];

}

当点击左边头像回到主界面的时候,想回到主界面,demo是又重新创建的一个新的,在项目中不可取。


2,当主界面进入二级页面,想去除手势。实现定制。

MMDrawerController.h 添加 

/* 2016-5-10 mxt 添加

  是否开启手势滑动出菜单*/

@property (assign,nonatomic) BOOL needSwipeShowMenu;//是否开启手势滑动出菜单

 

MMDrawerController.m 添加 

 

 

#pragma mark - Helpers

-(void)setupGestureRecognizers{

    

    pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCallback:)];

    [pan setDelegate:self];

    

    //[self.view addGestureRecognizer:pan];

    

    

    tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureCallback:)];

    [tap setDelegate:self];

    [self.view addGestureRecognizer:tap];

}

// 重写sett

- (void)setNeedSwipeShowMenu:(BOOL)needSwipeShowMenu{

    _needSwipeShowMenu = needSwipeShowMenu;

    if (needSwipeShowMenu) {

       // NSLog(@"--------needSwipeShowMenu---------------------------------- yes  ");

        [self.view addGestureRecognizer:pan];

    }else{

       // NSLog(@"--------needSwipeShowMenu---------------------------------- no  ");

          [self.view removeGestureRecognizer:pan];

    }

}

 

在使用的页面 添加 

 

- (void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

    NSLog(@" mine viewDidAppear  yes");

    kAPPDelegate.drawerController.needSwipeShowMenu = YES;  

}

- (void)viewWillDisappear:(BOOL)animated

{

    kAPPDelegate.drawerController.needSwipeShowMenu = NO;

}

 

 








MMDrawerController 使用遇到的问题及定制

标签:

原文地址:http://www.cnblogs.com/iOS-mt/p/5481179.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!