gpt4 book ai didi

ios - UICollectionView 删除空格/标题 iOS11

转载 作者:可可西里 更新时间:2023-11-01 04:10:33 25 4
gpt4 key购买 nike

我有一个 UICollection View ,看起来像这样(看到两个紫色和蓝色边框):

UICollectionView with issue

在 iOS 10 上没有标题/空格,但在 iOS11 上有。我已经尝试了这里提到的所有内容:How can I enable/disable section headers in UICollectionView programmatically?

我的代码目前看起来像这样:

- (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;
}

我的 FlowLayout 看起来像这样:

- (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;
}

我还验证了 UICollectionView 的 contentInset 已归零。

我错过了什么?为什么我的 UICollectionView 仍然有空格?

最佳答案

在 iOS 11 中,UIScrollView 发生了一些变化。

尝试设置 contentInsetAdjustmentBehavior属性

collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

关于ios - UICollectionView 删除空格/标题 iOS11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45374136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com