MMDrawerController 的实践,已经实现,几行简单的代码实现侧栏

 

学习方法,看readme,看给的Demo

看功能怎么实现的去模仿,个人感觉模仿是最快的学习方法

废话少说,上代码

导入MMDrawerController框架我就不多少了,之后做什么才是我们才关注的事情

首先介绍一下框架的基本机构,框架有中心,左右三个controller 所以要创建三个controller ,将三个控制器放在框架的指定位置即可,看代码理解


#import "AppDelegate.h"

//抽屉效果
#import "MMDrawerController.h"

//中心视图
#import "centerViewController.h"

//左视图
#import "leftViewController.h"

//右视图
#import "rightViewController.h"

//导航栏,此处是需要注意的地方,因为,如果只设置一个-控制器的,会出现导航栏不随着controller移动
#import "NaviViewController.h"

//这是reveal图像监控的同文件,专门的配置随后文章附上
#import <dlfcn.h>
@interface AppDelegate ()

//将抽屉效果升级为属性,全局持有
@property (nonatomic,strong) MMDrawerController *drawer;
@end

@implementation AppDelegate

//图像显示
- (void)loadReveal
{
    if (NSClassFromString(@"IBARevealLoader") == nil)
    {
        NSString *revealLibName = @"libReveal";
        NSString *revealLibExtension = @"dylib";
        NSString *error;
        NSString *dyLibPath = [[NSBundle mainBundle] pathForResource:revealLibName ofType:revealLibExtension];
        
        if (dyLibPath != nil)
        {
            NSLog(@"Loading dynamic library: %@", dyLibPath);
            void *revealLib = dlopen([dyLibPath cStringUsingEncoding:NSUTF8StringEncoding], RTLD_NOW);
            
            if (revealLib == NULL)
            {
                error = [NSString stringWithUTF8String:dlerror()];
            }
        }
        else
        {
            error = @"File not found.";
        }
        
        if (error != nil)
        {
            NSString *message = [NSString stringWithFormat:@"%@.%@ failed to load with error: %@", revealLibName, revealLibExtension, error];
            [[[UIAlertView alloc] initWithTitle:@"Reveal library could not be loaded" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
        }
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    UIViewController *left = [leftViewController new];
    left.view.backgroundColor = [UIColor whiteColor];
 // UIViewController *right = [rightViewController new];
    UINavigationController *leftNavi = [[UINavigationController alloc]initWithRootViewController:left];
   // UINavigationController*rightNavi = [[UINavigationController alloc]initWithRootViewController:right];
  // right.view.backgroundColor = [UIColor redColor];
    UIViewController *center = [centerViewController new];
    UINavigationController *centerNavi = [[NaviViewController alloc]initWithRootViewController:center];

//这里我只实现了左侧栏
    self.drawer = [[MMDrawerController alloc]initWithCenterViewController:centerNavi leftDrawerViewController:leftNavi rightDrawerViewController:nil];

    center.view.backgroundColor = [UIColor blueColor];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

//设置阴影效果
    [self.drawer setShowsShadow:NO];

//设置左侧栏打开时的宽度
    [self.drawer setMaximumLeftDrawerWidth:100];

//开启手势开启左侧栏,手势是框架自带的直接使用,可以自定义.,参照原来框架的readme实现
    [self.drawer setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];

//开启关闭手势
    [self.drawer setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];



    UIColor * tintColor = [UIColor colorWithRed:29.0/255.0
                                          green:173.0/255.0
                                           blue:234.0/255.0
                                          alpha:1.0];
    [self.window setTintColor:tintColor];
    [self.window setRootViewController:self.drawer];

//调用图像监控
    [self loadReveal];
    return YES;
}

 

 下面看一下一个导航的情况,好吧几乎看不出来了,

demo地址:https://github.com/lizhaojie001/Drawer.git

---恢复内容结束---

posted @ 2016-01-13 19:39  严_青  阅读(670)  评论(0编辑  收藏  举报