IOS-PPRevealViewController侧边栏

> 定义 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方法中 -
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch
return之前加上

     CGPoint poit = [touch locationInView:self.view ];
//        NSLog(@"%f,%d",poit.x,_wasClosed);
        if (poit.x >100) {
            if (!_wasClosed) {

                return YES;
            }else{
            return NO;
            }
        }

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。