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;
}
}