iOS侧拉栏抽屉效果Demo

7 篇文章 0 订阅
侧拉栏抽屉效果Demo
 需要导入第三方的类库如下:


抽屉效果所需第三方类库下载



效果:既可以两侧都实现抽屉效果也可只实现左侧栏或者右侧栏的抽屉效果
 
                                   


关于抽屉效果主要是AppDelegate的代码

AppDelegate.h文件代码:

<span style="font-size:18px;"><span style="font-size:18px;">#import <UIKit/UIKit.h>

@interface YJFAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end</span></span>

AppDelegate.m文件代码

<span style="font-size:18px;"><span style="font-size:24px;"><span style="font-size:18px;">#import "YJFAppDelegate.h"
#import "CustomizedNavigationController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
@implementation YJFAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //主视图
    FirstViewController *firstVC = [[FirstViewController alloc] init];
    //左边视图
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    //右边视图
    ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
    
    CustomizedNavigationController *navigationVC = [[CustomizedNavigationController alloc] initWithRootViewController:firstVC];
    

    CustomizedNavigationController *leftNavigationVC = [[CustomizedNavigationController alloc] initWithRootViewController:secondVC];

    CustomizedNavigationController *rightNavigationVC = [[CustomizedNavigationController alloc] initWithRootViewController:thirdVC];

    //抽屉管理 第三方
    //该第三方既可以只实现打开左侧栏也可以实现打开右侧栏,还可以同时都实现
    MMDrawerController *rooVC = [[MMDrawerController alloc] initWithCenterViewController:navigationVC leftDrawerViewController:leftNavigationVC rightDrawerViewController:rightNavigationVC];
    
    //只实现打开左侧栏
    //MMDrawerController *rooVCLeft = [[MMDrawerController alloc] initWithCenterViewController:navigationVC leftDrawerViewController:firstVC];
    //只实现打开右侧栏
    //MMDrawerController *rooVCRight = [[MMDrawerController alloc] initWithCenterViewController:navigationVC rightDrawerViewController:thirdVC];
    
    //指定window的根视图
    self.window.rootViewController = rooVC;
    //测了门的宽度
    [rooVC setMaximumLeftDrawerWidth:270];
    //设置侧拉门开与关的动画
    [rooVC setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [rooVC setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    //侧开内容展示效果
    //设置向左滑动打开右侧栏
    [[MMExampleDrawerVisualStateManager sharedManager] setRightDrawerAnimationType:MMDrawerAnimationTypeNone];
    //设置向右滑动打开左侧栏
    [[MMExampleDrawerVisualStateManager sharedManager] setLeftDrawerAnimationType:MMDrawerAnimationTypeNone];
    
    //
    [rooVC setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
        MMDrawerControllerDrawerVisualStateBlock block;
        block = [[MMExampleDrawerVisualStateManager sharedManager]
                 drawerVisualStateBlockForDrawerSide:drawerSide];
        if(block){
            block(drawerController, drawerSide, percentVisible);
        }

    }];
    
    



    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}</span>
</span>
</span>


  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值