0

在 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 运行应用程序,我不希望有条件布局代码。

4

1 回答 1

2

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

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

A translucent navigation bar just sits on top of its top view controller's view, while a not translucent one causes the view controller's view to resize accordingly.

To answer your question, you either manually set the navigationBar.translucent = NO, or, if you want to keep it translucent, you need to adjust the layout accordingly.

于 2013-09-20T10:30:37.543 回答