码迷,mamicode.com
首页 > 移动开发 > 详细

IOS-PPRevealViewController侧边栏

时间:2015-06-09 17:19:01      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:侧边栏   侧边推出   抽屉   

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

IOS-PPRevealViewController侧边栏

标签:侧边栏   侧边推出   抽屉   

原文地址:http://blog.csdn.net/u010742414/article/details/46427989

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!