storyboard设计两级TabBarController,第二级Tabbar的位置问题

来源:互联网 发布:下载软件推荐 知乎 编辑:程序博客网 时间:2024/05/17 22:21

这个问题已经解决了

但是还是有点迷糊

感谢 willingseal  前辈的 热心指点(http://my.csdn.net/willingyatou/)


 

二级TarBarController布局如上图所示

 

运行效果图如下

 





后面两个图中,我把第二级的TabBarController的位置调整到了上面,代码如下

     CGRect tabBarFrame = [self.tabBar frame];

    tabBarFrame.origin.y = 100;

    [self.tabBar setFrame:tabBarFrame];

这时,虽然tabbar上去了,但是它以前在下面的位置却变成了黑色,

请问怎么把View扩展下来,我通过设置setFrame,好像没有任何效果

这种两级Tabbar应该很普遍吧,主Tabbar在下面,次Tabbar在上面


我一开始直接在ViewController2-1里面viewDidLoad直接设置 self.view的setFrame,没有效果

然后跟踪其中的View的setFrame函数,发现在我setFrame之后,系统还会调用还几次setFrame,直接把我设置的高度冲掉了

height最终打印出来都是362

在willingseal 前辈的 热心指点下,我在ViewController2-1的viewDidLoad调用如下代码

UIView *contentView;

    if ( [[self.tabBarController.view.subviewsobjectAtIndex:0]isKindOfClass:[UITabBarclass]] )

        contentView = [self.tabBarController.view.subviewsobjectAtIndex:1];

    else

        contentView = [self.tabBarController.view.subviewsobjectAtIndex:0];

    contentView.frame = CGRectMake(contentView.bounds.origin.x,  contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height +self.tabBarController.tabBar.frame.size.height);

就可以达到如下的效果了



或者我直接在TabBarViewController1-2的viewDidLoad调用如下代码

    UIView *contentView;

    if ( [[self.view.subviewsobjectAtIndex:0]isKindOfClass:[UITabBarclass]] )

        contentView = [self.view.subviewsobjectAtIndex:1];

    else

        contentView = [self.view.subviewsobjectAtIndex:0];

    contentView.frame = CGRectMake(contentView.bounds.origin.x,  contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height +self.tabBarController.tabBar.frame.size.height);

也可以达到设置view的height的效果

最后还是要好好感谢willingseal,她非常热心

原创粉丝点击