IOS-PPRevealViewController側邊欄

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.