Question

When running my app on ios7 I noticed that my child view controllers had a point of origin that started under its parent view controller's navigation bar, this wasn't the case on ios6.

This is the code that I'm using when adding the child view controller:

- (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

}

When I adjust the child view controller's frame I'm able to see it however ideally I don't want to have conditional layout code for if the user is running the app from iOS 6 or 7.

Was it helpful?

Solution

The reason is simple: the default value for the translucent property of the navigation bar.

Up to iOS 6.1 the default value was NO, but starting from iOS7 the default value is 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top