你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS-PPRevealViewController側邊欄

IOS-PPRevealViewController側邊欄

編輯:IOS開發綜合

> 定義 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;
            }
        }
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved