2014-12-05 56 views
0

我有两个viewControllers iPad就像facebook sidepanel一样。有LeftViewController,当我点击中心viewController上的按钮时,它会切换。它在CenterViewController的顶部滑动。但它只涵盖centerViewController的50%。嵌套UINavigationController的最佳方法

我应该可以将新视图添加到左侧viewController并且可以推送。

什么是实现这一目标的最佳方法。

+0

我不明白,你问滑动边栏(滑出或进入)? – 2014-12-05 05:33:36

+0

是的。我有滑动侧栏,我应该能够在视图之间推送和弹出。 – 2014-12-05 05:38:43

+0

您是否在寻找带侧边栏菜单的抽屉式控制器?像这个链接https://www.cocoacontrols.com/controls/mmdrawercontroller--2 – Esha 2014-12-05 05:40:59

回答

1

请检查该链接

Sliding Drawers

[SideMenus]

这包含不同的抽屉,并迅速数太多。可能是这个链接会对你有所帮助。

+1

是@ kampai,但如果任何用户想知道一些更好的库,那么作为对用户有帮助的东西的答案链接应该在那里。我们可以在这里设置链接到git或任何仓库,所以我们可以给链接作为答案。 :) – Esha 2014-12-05 06:22:14

0

你可以在view.see下面添加滑入侧栏。

在.h文件中指定的属性

UIView*menuDrawer; 

@property(readonly,nonatomic)UISwipeGestureRecognizer*recognizer_open,*recognizer_close; 
@property(readonly,nonatomic) int menuDrawerX,menuDrawerWidth; 

//自定义幻灯片菜单

添加该代码在viewDidLoad中

int statusBarHeight=[UIApplication sharedApplication].statusBarFrame.size.height-20; 
    menuDrawerWidth=self.view.frame.size.width*0.65;//you can adjust width 
    menuDrawerX=self.view.frame.origin.x-menuDrawerWidth; 
    menuDrawer=[[UIView alloc]initWithFrame:CGRectMake(menuDrawerX, self.view.frame.origin.y+statusBarHeight, menuDrawerWidth,self.view.frame.size.height-statusBarHeight)]; 
    menuDrawer.backgroundColor=[UIColor 
           whiteColor]; 
    recognizer_close=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipes:)]; 
    recognizer_open=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipes:)]; 
    recognizer_close.direction=UISwipeGestureRecognizerDirectionLeft; 
    recognizer_open.direction=UISwipeGestureRecognizerDirectionRight; 


    [self.view addGestureRecognizer:recognizer_close]; 
    [self.view addGestureRecognizer:recognizer_open]; 
    [self.view addSubview:menuDrawer]; 

添加此方法

-(void)handleSwipes:(UISwipeGestureRecognizer*)sender 
{ 
    [self drawerAnimation]; 

} 

通话THI S分析,如果您分配一个按钮,也可以设置一个按钮,选择

-(void)drawerAnimation 
{ 

[UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:-5]; 

    CGFloat new_x = 0; 
    if (menuDrawer.frame.origin.x < self.view.frame.origin.x) { 
     new_x=menuDrawer.frame.origin.x + menuDrawerWidth; 
     } 
    else 
    { 
     new_x=menuDrawer.frame.origin.x - menuDrawerWidth; 
    } 
    menuDrawer.frame=CGRectMake(new_x, menuDrawer.frame.origin.y, menuDrawer.frame.size.width, menuDrawer.frame.size.height); 
    [UIView commitAnimations]; 


} 

它会正常工作,你可以在这些滑入侧栏菜单中添加的UITableView或其他控件。

您可以通过statusBarHeight和menuDrawerWidth调整高度和宽度。