0

I have a navigation controller and a view controller inside of the navigation controller. The view controller calls the navigation controller to push a view:

    `MYVC *myvc = [MYVC new]`;
    `[self.navigationController pushViewController:myvc
                                         animated:YES]`;

Inside of MYVC I have the following logic for laying out my collection view:

- (void)viewDidLayoutSubviews {
     [super viewDidLayoutSubviews];

_collectionView.frame = CGRectMake(0, 
                                   0,
                                   self.view.frame.size.width,
                                   self.view.frame.size.height - height);
}

This works fine for when I first load my vc as the collection view is loaded under my nav bar. However when I push my vc it looks like the following: Collection View

Overlap

Above the divider line is my nav bar and the red is my colleciton view. It looks like the collection view is laid out under my navigation bar. If I drag on my collection view it lays out properly. If I try changing the _collectionView frame's y position to self.navigationController.navigationBar.frame.size.height however I get a large whitespace above my collection view after I drag on my collection view. How can I get it to be laid out properly the first time? Do I have to force layout? Is there some reason my nav bar isn't taken into account for the vc until I drag in the scroll view?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
MichaelGofron
  • 1,310
  • 4
  • 15
  • 29
  • It seems to me that the issue might be related to the fact that the view controller is actually *under* the navigation bar. I'm not push why that would be the case as the view controller is inited in the navigation bar. – MichaelGofron Mar 28 '19 at 14:02
  • Anyone have any ideas or can point me to a similar case where this happens? I haven't found anything on SO – MichaelGofron Apr 02 '19 at 19:06

0 Answers0