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;
            }
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值