您的位置:首页 > 其它

11----MMDrawerConcroller的简单使用

2015-09-24 10:12 253 查看
    学习的时间总是过得很快,虽然每一天的起床都很煎熬,但到教室后一天很快就过去了。时间越来越少,会的东西也越来越多,进入项目二的学习后,接触的第三方框架也越来越多,比如像项目二的大框架就是一个MMDrawerController,创建代码如下

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    self.view.backgroundColor = [UIColor clearColor];

    

    //从故事板(storybord)中获取控制器对象

    UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    

    [[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(_setAnimation) name:kStyleNotification object:nil];

    

    //设置左边的控制器

    self.leftDrawerViewController = [storybord instantiateViewControllerWithIdentifier:@"LeftVC"];

    

    //设置中间的控制器

    self.centerViewController = [storybord instantiateViewControllerWithIdentifier:@"CenterVC"];

    

    //设置右边的控制器

    self.rightDrawerViewController = [storybord instantiateViewControllerWithIdentifier:@"RightVC"];

    

    //设置阴影

    [self setShowsShadow:YES];

    

    //设置两边的宽度

    [self setMaximumLeftDrawerWidth:160.0];

    [self setMaximumRightDrawerWidth:60.0];

    

    //设置手势的作用区域

    [self setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];

    [self setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

    

    //配置动画的回调函数

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

        MMDrawerControllerDrawerVisualStateBlock block;

        block = [[MMExampleDrawerVisualStateManagersharedManager]drawerVisualStateBlockForDrawerSide:drawerSide];

        if (block) {

            block(drawerController,drawerSide,percentVisible);

        }

        

    }];

 

    //设置动画

    

    [self _setAnimation];

    

    

}

//设置动画

- (void)_setAnimation

{

    //从数据中拿到选中的样式

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSInteger style = [[defaults objectForKey:kAnimationStyle]integerValue];

    //根据样式的枚举值设置动画

    [[MMExampleDrawerVisualStateManager sharedManager] setLeftDrawerAnimationType:style];

    [[MMExampleDrawerVisualStateManager sharedManager] setRightDrawerAnimationType:style];

}

    学习的时间总是过得很快,虽然每一天的起床都很煎熬,但到教室后一天很快就过去了。时间越来越少,会的东西也越来越多,进入项目二的学习后,接触的第三方框架也越来越多,比如像项目二的大框架就是一个MMDrawerController,创建代码如下

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    self.view.backgroundColor = [UIColor clearColor];

    

    //从故事板(storybord)中获取控制器对象

    UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    

    [[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(_setAnimation) name:kStyleNotification object:nil];

    

    //设置左边的控制器

    self.leftDrawerViewController = [storybord instantiateViewControllerWithIdentifier:@"LeftVC"];

    

    //设置中间的控制器

    self.centerViewController = [storybord instantiateViewControllerWithIdentifier:@"CenterVC"];

    

    //设置右边的控制器

    self.rightDrawerViewController = [storybord instantiateViewControllerWithIdentifier:@"RightVC"];

    

    //设置阴影

    [self setShowsShadow:YES];

    

    //设置两边的宽度

    [self setMaximumLeftDrawerWidth:160.0];

    [self setMaximumRightDrawerWidth:60.0];

    

    //设置手势的作用区域

    [self setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];

    [self setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

    

    //配置动画的回调函数

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

        MMDrawerControllerDrawerVisualStateBlock block;

        block = [[MMExampleDrawerVisualStateManagersharedManager]drawerVisualStateBlockForDrawerSide:drawerSide];

        if (block) {

            block(drawerController,drawerSide,percentVisible);

        }

        

    }];

 

    //设置动画

    

    [self _setAnimation];

    

    

}

//设置动画

- (void)_setAnimation

{

    //从数据中拿到选中的样式

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSInteger style = [[defaults objectForKey:kAnimationStyle]integerValue];

    //根据样式的枚举值设置动画

    [[MMExampleDrawerVisualStateManager sharedManager] setLeftDrawerAnimationType:style];

    [[MMExampleDrawerVisualStateManager sharedManager] setRightDrawerAnimationType:style];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: