Implementation of the collection in the form of a container - additional white space at the top

I have an application that uses the Nav Contoller as the initial VC, which then has the root UIViewContoller, which contains the UIView in the upper half, and the UIContainerView at the bottom. In UIContanerView, I embed a working UICollectionView containing image buttons that jump to detailed views.

The problem is that white space is displayed at the top of the UICollectionView. Given that it is about 64 pixels high, it looks like a halo of the line Nav Bar 44px + Status bar 20px = 64.

Extra space around 64px in my UICollectionView (I set it gray)

And if I scroll through everything, everything looks fine and works as expected, and this also allows me to show what I expected the layout to look like at startup:

I expected the launch layout to look like

Below is a snippet of my storyboard if that helps:

Storyboard

+6
source share
1 answer

yes, this may be due to the fact that the child view controller built into the container view gets the impression that it is a direct child of the UINavigationController, which, in turn, makes the View collector from above 64-bit inserts.

To resolve this issue, in your child node controller interface designer uncheck the scrollView checkbox of the insert

In your child view controller interface designer, uncheck scrollView insets

This should solve your problem.

UPDATE

As Dan suggested, we can also fix it programmatically by calling

automaticallyAdjustsScrollViewInsets = false 

in viewDidLoad () of your UIViewController

+10
source

All Articles