IOS-PPRevealViewController sidebar
> DefinitionPPRevealViewController
PPRevealSideViewControllerDelegate@property (strong, nonatomic) PPRevealSideViewController *revealSideViewController;
> Initialization
HomeViewController * con = [[HomeViewController alloc] init]; UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController: con]; _ metadata = [PPRevealSideViewController alloc] initWithRootViewController: nav]; _ revealSideViewController. delegate = self; _ revealSideViewController. options = PPRevealSideOptionsNone; // shadow of the intermediate interface _ revealSideViewController. bouncingOffset = 0; _ revealSideViewController. panInteractionsWhenClosed = PPRevealSideInteractionNavigationBar | PPRevealSideInteractionContentView; // you can slide the navigation bar and content to display the self. window. rootViewController = _ revealSideViewController;
-(PPRevealSideDirection) pprevealSideViewController :( PPRevealSideViewController *) controller directionsAllowedForPanningOnView :( UIView *) view {return pprevealsidedireleft; // only supports left sliding}
> Use
Add a sidebar to the homepage
In HomeViewController-(void) viewWillAppear :( BOOL) animated {[super viewWillAppear: YES]; SideViewController * side = [[SideViewController alloc] init]; [self. revealSideViewController preloadViewController: side forSide: PPRevealSideDirectionLeft];}
Go to the sidebar
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);
From the sidebar to the previous attempt, self is the sidebar
[self.revealSideViewController popViewControllerAnimated:YES];
Go to the home page from other pages
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);
From other pages to the sidebar
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);
Enter a New View
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ViewController]; [self.revealSideViewController popViewControllerWithNewCenterController:nav animated:YES]; PP_RELEASE(ViewController); PP_RELEASE(nav);
Postscript
The Sidebar function is available only when sliding within a fixed screen range is required. In the. m method-
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch
Add
CGPoint poit = [touch locationInView:self.view ];// NSLog(@"%f,%d",poit.x,_wasClosed); if (poit.x >100) {\ if (!_wasClosed) { return YES; }else{ return NO; } }