Search code examples
iosuinavigationbarios7

iOS7: UICollectionView appearing under UINavigationBar


I've been building on iOS 7 for a while now but I've yet to get this solved, I have a number of views with autolayout enabled that were created in Storyboard and are displayed with a standard UINavigationController. The majority are fine, but the ones based on UICollectionView always place themselves under the navigation bar, unless I set the translucency to NO. I've tried the edgesExtended trick but that doesn't seem to solve it, I don't necessarily mind having the translucency off but I'd like to solve it cleaner.


Solution

  • I had this problem before, just set the edge insents of the collection view with a top margin:

     [self.myCollectionVC.collectionView setContentInset:UIEdgeInsetsMake(topMargin, 0, 0, 0)];
    

    Where topMargin is the size of the nav bar, or whatever point you want the collection to start scrolling.

    In this way, your collection view will start scrolling just below the navigation bar, and at the same time it will fill the whole screen and you will see it if your nav bar is translucent.