侧滑菜单 RESideMenu-master 的使用

RESideMenu GitHub地址

首先在 github 上下载 resideMenu

自带 Demo 分为纯代码版,和 storyboards 版本,其实差不多.我用的是纯代码版本

1.在 APPDelegate 中添加RESideMenu 为根视图

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

self.window= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

UINavigationController*navigationController = [[UINavigationControlleralloc]initWithRootViewController:[[ZLBRootViewControlleralloc]init]];

ZLBLeftViewController*leftViewController = [[ZLBLeftViewControlleralloc]init];

RESideMenu*sideMenuViewController = [[RESideMenualloc]initWithContentViewController:navigationControllerleftMenuViewController:leftViewControllerrightMenuViewController:nil];

sideMenuViewController.backgroundImage= [UIImageimageNamed:@"Stars"];

sideMenuViewController.menuPreferredStatusBarStyle=1;// UIStatusBarStyleLightContent

sideMenuViewController.delegate=self;

sideMenuViewController.contentViewShadowColor= [UIColorblackColor];

sideMenuViewController.contentViewShadowOffset=CGSizeMake(0,0);

sideMenuViewController.contentViewShadowOpacity=0.6;

sideMenuViewController.contentViewShadowRadius=12;

sideMenuViewController.contentViewShadowEnabled=YES;

self.window.rootViewController= sideMenuViewController;

self.window.backgroundColor= [UIColorwhiteColor];

[self.windowmakeKeyAndVisible];

returnYES;

}

RESideMenu*sideMenuViewController = [[RESideMenualloc]initWithContentViewController:navigationControllerleftMenuViewController:leftViewControllerrightMenuViewController:nil];

关键是这句 ,contentViewController 就是刚进去看到的界面,, leftMenuViewController 就是左侧滑的 ViewController,, 没有可以设置为nil


2.根视图上添加以下代码

- (void)viewDidLoad {

[superviewDidLoad];

self.navigationItem.leftBarButtonItem= [[UIBarButtonItemalloc]initWithTitle:@"Left"

style:UIBarButtonItemStylePlain

target:self

action:@selector(presentLeftMenuViewController:)];

self.navigationItem.rightBarButtonItem= [[UIBarButtonItemalloc]initWithTitle:@"Right"

style:UIBarButtonItemStylePlain

target:self

action:@selector(presentRightMenuViewController:)];

UIImageView*imageView = [[UIImageViewalloc]initWithFrame:self.view.bounds];

imageView.contentMode=UIViewContentModeScaleAspectFill;

imageView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

imageView.image= [UIImageimageNamed:@"Balloon"];

[self.viewaddSubview:imageView];

}

presentLeftMenuViewController 和 presentRightMenuViewController 是 UIViewController 的分类方法,它已经写好,可以直接使用的

3.点击菜单上的不同的按钮   到不同的页面 (菜单是个 TableView)


- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath

{

[tableViewdeselectRowAtIndexPath:indexPathanimated:YES];

switch(indexPath.row) {

case0:

[self.sideMenuViewControllersetContentViewController:[[UINavigationControlleralloc]initWithRootViewController:[[DEMOFirstViewControlleralloc]init]]

animated:YES];

[self.sideMenuViewControllerhideMenuViewController];

break;

case1:

[self.sideMenuViewControllersetContentViewController:[[UINavigationControlleralloc]initWithRootViewController:[[DEMOSecondViewControlleralloc]init]]

animated:YES];

[self.sideMenuViewControllerhideMenuViewController];

break;

default:

break;

}

}


所以说 so easy 

你可能感兴趣的:(侧滑菜单 RESideMenu-master 的使用)