嵌套UINavigationController的最佳方法

时间:2014-12-05 05:09:39

标签: ios swift uiviewcontroller uinavigationcontroller

我有两个viewControllers用于iPad就像facebook侧面板一样。当我点击中心LeftViewController上的按钮时,会viewController切换。它滑动在CenterViewController的顶部。但它仅涵盖centerViewController的50%。

我应该能够向左viewController添加新视图并且可以推送。

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

2 个答案:

答案 0 :(得分:1)

请查看此链接

Sliding Drawers

[SideMenus]

这包含不同的抽屉,很少有抽奖。可能这个链接会对你有所帮助。

答案 1 :(得分:0)

您可以在视图中添加滑入式侧栏。请参阅我的代码。

在.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];

}

调用此方法,如果您正在分配按钮,也可以设置按钮的选择器

-(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调整高度和宽度。