UICollectionView removes space / title of iOS11

I have a UICollection view that looks like this (see two purple and blue borders):

UICollectionView with issue

There is no title / space on iOS 10, but there is on iOS11. I tried everything that was mentioned here: How to enable or disable section headers in a UICollectionView programmatically?

And now my code looks like this:

- (void) viewDidLoad { [super viewDidLoad]; autocompleteLayout = [[SQLProAutocompleteFlowLayout alloc] init]; autocompleteLayout.headerReferenceSize = CGSizeZero; autocompleteCollectionView = [[UICollectionView alloc] initWithFrame: CGRectZero collectionViewLayout: autocompleteLayout]; autocompleteCollectionView.insetsLayoutMarginsFromSafeArea = NO; [self.view addSubview: autocompleteCollectionView]; // removed layout code (leftAnchor, rightAnchor, topAnchor, bottomAnchor). autocompleteCollectionView.delegate = self; autocompleteCollectionView.dataSource = self; // Removed nib register code self.view.layer.borderColor = [UIColor redColor].CGColor; self.view.layer.borderWidth = 1; autocompleteCollectionView.layer.borderColor = [UIColor blueColor].CGColor; autocompleteCollectionView.layer.borderWidth = 2; } - (CGSize) collectionView: (UICollectionView *) collectionView layout: (UICollectionViewLayout *) collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return CGSizeZero; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section { return CGSizeZero; } 

And my FlowLayout looks like this:

 - (void) setupLayout { self.minimumInteritemSpacing = 0; self.minimumLineSpacing = 0; self.scrollDirection = UICollectionViewScrollDirectionVertical; } // End of setupLayout - (void) prepareLayout { [super setItemSize: [self itemSize]]; [super setSectionInset: [self sectionInset]]; self.minimumLineSpacing = 0; [super prepareLayout]; } // End of prepareLayout - (CGFloat) itemWidth { return self.collectionView.frame.size.width; } - (CGSize) itemSize { CGSize result = CGSizeMake(self.collectionView.frame.size.width, rowHeight); return result; } - (void) setItemSize:(CGSize)itemSize { self.itemSize = CGSizeMake(self.collectionView.frame.size.width, rowHeight); } - (CGPoint) targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset { return CGPointZero; } 

I also checked that the UICollectionView contentInset is not null.

What am I missing? Why does my UICollectionView still have spaces?

+5
source share
2 answers

There are some changes to UIScrollView in iOS 11.

Try setting the contentInsetAdjustmentBehavior property

 collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; 
+14
source

Try the following:

  self.automaticallyAdjustsScrollViewInsets = false - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 0; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 0; } - (UIEdgeInsets)collectionView: (UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(-25,0,0,0); // top, left, bottom, right } 
+1
source

Source: https://habr.com/ru/post/1270325/


All Articles