Removing extra space at the top of uicollectionview

I have a xib where a button and a uicollectionview are displayed like this:

enter image description here

Now when I run it, it looks like this:

enter image description here

I want to remove the extra space above the photos. I want to show pictures just below the button. I also haven't added a header section to the xib. But, when I scroll up, the images move up and down under the buttton too.This means the frame starts from just below the button, but I get extra free space.

So, can anyone help me remove the extra space?

+3


source to share


2 answers


Add this code to your controller class

- (void)viewDidLoad 
{
    [super viewDidLoad];  
    self.automaticallyAdjustsScrollViewInsets = NO;
}

      



Here is a doc for automaticallyAdjustsScrollViewInsets


Default is YES, which allows the view controller to customize its scroll inserts in response to areas of the screen consumed by the status bar, navigation bar, toolbar, or tab bar. Set to NO if you want to control the scroll insertion settings yourself, for example, when there is more than one scroll in the view hierarchy.

+13


source


I had the same problem. What a job for me was to set automaticallyAdjustsScrollViewInsets = NO

not only on the ViewController containing the CollectionView, but also on its parent ViewController, because the child ViewController was in the ContainerView.



This can also be done in the interface builder: Auto adjust scrolling in view mode

+2


source







All Articles