iOS项目框架搭建之RESideMenu+RDVTabBarController+MLNavigationController

简介

RESideMenu

RESideMenu是一款非常优秀的侧边栏框架。主要特色功能包括:支持左右侧边栏、侧边栏+背景图+ContentViewController缩放、自定义过渡动画、为ContentViewController添加阴影。

基本使用:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
   
    UIViewController *rootController = [[contentViewController all] init];//主视图
    DEMOLeftMenuViewController *leftMenuViewController = [[DEMOLeftMenuViewController alloc] init];//左侧边
    DEMORightMenuViewController *rightMenuViewController = [[DEMORightMenuViewController alloc] init];//右侧边
    
    RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:rootController
                                                                    leftMenuViewController:leftMenuViewController
                                                                   rightMenuViewController:rightMenuViewController];
    sideMenuViewController.backgroundImage = [UIImage imageNamed:@"menu-background"];//初始化
    sideMenuViewController.menuPreferredStatusBarStyle = 1; // UIStatusBarStyleLightContent
    sideMenuViewController.animationDuration = 0.15;
    sideMenuViewController.delegate = self;
    self.window.rootViewController = sideMenuViewController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}


具体使用方法请查看该项目github主页。

RDVTabBarController

RDVTabBarController是一款支持旋转屏ios7风格TabbarController,支持iPad和iPhone、支持横向和纵向方向、可以用在UINavigationController
  可定制的Badge。

基本使用:

        DEMOContentFirstViewController *firstViewController = [[DEMOContentFirstViewController alloc] init];
        DEMOContentSecondViewController *secondViewController = [[DEMOContentSecondViewController alloc] init];
        DEMOContentThirdViewController *thirdViewController = [[DEMOContentThirdViewController alloc] init];

        RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
       [tabBarController setViewControllers:@[firstViewController, secondViewController,thirdViewController]];
        [tabBarController.view setBackgroundColor:[UIColor clearColor]];
        
        self.rootViewController = tabBarController;

        [self customizeTabBarForController:tabBarController];


MLNavigationController

MLNavigationController是类似网易新闻app/新浪微博app中手指右滑屏幕返回上一层视图的交互NavigationController,简单易用。

基本使用方法:

DEMOContentFirstViewController *firstViewController = [[DEMOContentFirstViewController alloc] init];
MLNavigationController *firstNavigationController = [[MLNavigationController alloc]
                                                             initWithRootViewController:firstViewController];


组合

当把这三个框架整合到一起就是一个带侧边栏和底部导航的大型应用基本模版,外加右滑返回功能。是不是很酷呢?

第一步,确定根导航controller。很明显,这里的根导航controller就是RESideMenu,按照上面的代码可以直接贴到项目中就可以使用。

第二步,将RDVTabBarController连接到RESideMenu的一个childController。根导航controller下面的一个childController应该要使用RDVTabBarController导航,可以单独建一个contentRootController,再自定义它要导航的菜单。

contentRootController初始化:

+(RootViewController*)shareInstance{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        RootViewController *root = [[RootViewControlleralloc]init];
        __defaultController = root;
    });
    return__defaultController;
}
设置controllers并使用 MLNavigationController

- (RDVTabBarController*)setupViewControllers {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        DEMOContentFirstViewController *firstViewController = [[DEMOContentFirstViewController alloc] init];
        MLNavigationController *firstNavigationController = [[MLNavigationController alloc]
                                                             initWithRootViewController:firstViewController];
        DEMOContentSecondViewController *secondViewController = [[DEMOContentSecondViewController alloc] init];
        MLNavigationController *secondNavigationController = [[MLNavigationController alloc]
                                                              initWithRootViewController:secondViewController];
        
        DEMOContentThirdViewController *thirdViewController = [[DEMOContentThirdViewController alloc] init];
        MLNavigationController *thirdNavigationController = [[MLNavigationController alloc]
                                                             initWithRootViewController:thirdViewController];
  
        RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
        [tabBarController setViewControllers:@[firstNavigationController, secondNavigationController,thirdNavigationController]];
        [tabBarController.view setBackgroundColor:[UIColor clearColor]];
        __tabBarController = tabBarController;
        [self customizeTabBarForController:tabBarController];
    });
    return __tabBarController;
}

使用contentRootController

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *rootController = [[RootViewController shareInstance] setupViewControllers];
DEMOLeftMenuViewController *leftMenuViewController = [[DEMOLeftMenuViewController alloc] init];
DEMORightMenuViewController *rightMenuViewController = [[DEMORightMenuViewController alloc] init];
RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:rootController                                                                    
                                                                leftMenuViewController:leftMenuViewController              
                                                                rightMenuViewController:rightMenuViewController];
至此, 一个带侧边栏和底部导航外加右滑返回的的大型应用基本模版完成了,so easy。

但是还有一个地方需要修改:contentRootController下的childController不能右滑弹出侧边栏,这个问题我会在下一篇文章解决。

你可能感兴趣的:(iOS)