子视图控制器部分显示在父视图控制器的导航栏下

时间:2013-09-20 10:18:00

标签: ios layout containers viewcontroller childviewcontroller

在ios7上运行我的应用程序时,我注意到我的子视图控制器在其父视图控制器的导航栏下有一个原点,在ios6上不是这样。

这是我在添加子视图控制器时使用的代码:

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if (!self.selectionBarViewController) //self.selectionBarViewController is the child view controller
    {

        self.selectionBarViewController = [[UCIScrollSelectionBarViewController alloc] init];

        self.selectionBarViewController.view.frame = CGRectMake(0.0f,
                                                                0.0f,
                                                                self.view.frame.size.width,
                                                                44.0f);

        self.selectionBarViewController.dataSource = self;
        self.selectionBarViewController.delegate = self;

        [self addChildViewController:self.selectionBarViewController];
        [self.view addSubview:self.selectionBarViewController.view];
        [self.selectionBarViewController didMoveToParentViewController:self];

        [self.selectionBarViewController beginAppearanceTransition:YES
                                                          animated:YES];

    }

    //More set up code here

}

当我调整子视图控制器的框架时,我能够看到它,但理想情况下,如果用户从iOS 6或7运行应用程序,我不希望有条件布局代码。

1 个答案:

答案 0 :(得分:2)

原因很简单:导航栏的半透明属性的默认值。

直到iOS 6.1,默认值为NO,但从iOS7开始,默认值为YES。

半透明导航栏位于其顶部视图控制器视图的顶部,而不是半透明的导航栏会导致视图控制器的视图相应调整大小。

要回答您的问题,您可以手动设置navigationBar.translucent = NO,或者,如果您想保持半透明状态,则需要相应地调整布局。

相关问题