GitHub上有相关demo,都是基于sb的,这里就不再赘述,主要说一下基于纯代码的使用方式。
SWRevealViewController可以通过cocoapod安装。
这里假设主控制器(地图)是A,侧滑栏是B。
1.在AppDelegate中代码如下:
B * b =[[B alloc]init];
A * a =[[A alloc]init];
NavViewController* nav = [[NavViewController alloc]initWithRootViewController:a];
SWRevealViewController * sw = [[SWRevealViewController alloc]initWithRearViewController:b frontViewController:nav];
self.window.rootViewController = sw;
2.在A控制器中代码如下:
- (void)viewDidLoad {
SWRevealViewController*revealViewController =self.revealViewController;
if(revealViewController)
{
[self.navigationItem.leftBarButtonItemsetTarget:self.revealViewController];
[self.navigationItem.leftBarButtonItemsetAction:@selector(revealToggle: )];
[self.navigationController.navigationBaraddGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
}
//点击打开侧滑
- (void)clickLeft {
[self.revealViewController revealToggleAnimated:YES];
}
3.在B控制器中代码如下(跳转页面C):
C* c =[[C alloc]init];
[self.revealViewControllerpushFrontViewController: c animated:YES];