PPRevealViewController
PPRevealSideViewControllerDelegate
@property (strong, nonatomic) PPRevealSideViewController *revealSideViewController;
HomeViewController* con = [[HomeViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:con];
_revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];
_revealSideViewController.delegate = self;
_revealSideViewController.options = PPRevealSideOptionsNone;//中间界面阴影
_revealSideViewController.bouncingOffset = 0;
_revealSideViewController.panInteractionsWhenClosed = PPRevealSideInteractionNavigationBar|PPRevealSideInteractionContentView;//navBar和内容都支持滑动弹出侧边栏
self.window.rootViewController = _revealSideViewController;
- (PPRevealSideDirection)pprevealSideViewController:(PPRevealSideViewController*)controller directionsAllowedForPanningOnView:(UIView*)view{
return PPRevealSideDirectionLeft;//只支持左滑
}
在主页中添加侧边栏
在HomeViewController中
-(void )viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
SideViewController* side = [[SideViewController alloc]init];
[self.revealSideViewController preloadViewController:side forSide:PPRevealSideDirectionLeft];
}
进入到侧边栏
SideViewController *c = [[SideViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController* nav = [[UINavigationController alloc]initWithRootViewController:c];
[self.revealSideViewController pushViewController:nav onDirection:PPRevealSideDirectionLeft withOffset:70 animated:YES];
PP_RELEASE(c);
PP_RELEASE(nav);
从侧边栏弹出到上一个试图,self为侧边栏
[self.revealSideViewController popViewControllerAnimated:YES];
从其它页面进入到主页
HomeViewController *c = [[HomeViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *n = [[UINavigationController alloc] initWithRootViewController:c];
[self.revealSideViewController popViewControllerWithNewCenterController:n animated:YES];
PP_RELEASE(c);
PP_RELEASE(n);
从其它页面进入到侧边栏
HomeViewController* con = [[HomeViewController alloc]initWithNibName:nil bundle:nil];
UINavigationController* nav =[[UINavigationController alloc]initWithRootViewController:con];
[self.revealSideViewController popViewControllerWithNewCenterController:nav animated:YES completion:^{
SideViewController *c = [[SideViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController* nav = [[UINavigationController alloc]initWithRootViewController:c];
[self.revealSideViewController pushViewController:nav onDirection:PPRevealSideDirectionLeft withOffset:70 animated:YES];
PP_RELEASE(c);
PP_RELEASE(nav);
}];
PP_RELEASE(con);
PP_RELEASE(nav);
进入一个新视图
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ViewController];
[self.revealSideViewController popViewControllerWithNewCenterController:nav animated:YES];
PP_RELEASE(ViewController);
PP_RELEASE(nav);
当需要限定屏幕固定范围滑动的时候才有侧边栏功能,请在.m方法中
-
return之前加上
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch
CGPoint poit = [touch locationInView:self.view ];
// NSLog(@"%f,%d",poit.x,_wasClosed);
if (poit.x >100) {
if (!_wasClosed) {
return YES;
}else{
return NO;
}
}
原文地址:http://blog.csdn.net/u010742414/article/details/46427989