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

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

转载于:https://www.cnblogs.com/zhao-jie-li/p/5128282.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值