【发布时间】:2014-06-06 04:46:01
【问题描述】:
我有一个集合视图,它本身是委托和数据源,并且布局定义如下:
- (id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self){
self.dataSource = self;
self.delegate = self;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 0;
layout.sectionInset = UIEdgeInsetsMake(0, 8, 0, 8);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.footerReferenceSize = CGSizeMake(1, 70);
layout.itemSize = CGSizeMake(60, 70);
layout.minimumInteritemSpacing = 4.0f;
[self setCollectionViewLayout:layout];
}
return self;
}
代码运行正常,除了 minimuminteritemspacing。
结果是一个集合视图,其中每个部分中的项目根本没有任何间距。
我设置的最小间距值应该向上调整,而不是向下调整,对吗?
那么为什么我看到的结果和这个屏幕上的一样呢? (我对每个收藏品进行了着色,以便清楚地看到没有间距)
更多细节,这里是我正在记录的帧,你可以看到第三个项目正好在第二个项目之后开始(145 像素 = 85(previousitem.x) + 60(previousitem.width)),没有间距.
2014-04-22 10:25:49.954 App[15172:60b] self <PhotoIndexCollectionViewCell: 0x16576630; baseClass = UICollectionViewCell; frame = (8 0; 60 70); layer = <CALayer: 0x165777a0>>
2014-04-22 10:25:49.955 App[15172:60b] self <PhotoIndexCollectionViewCell: 0x16578380; baseClass = UICollectionViewCell; frame = (85 0; 60 70); layer = <CALayer: 0x16578520>>
2014-04-22 10:25:49.955 App[15172:60b] self <PhotoIndexCollectionViewCell: 0x16586620; baseClass = UICollectionViewCell; frame = (145 0; 60 70); layer = <CALayer: 0x165866c0>>
我在这里误会了什么?
我什至尝试添加这个方法,它实际上是为每个部分调用的,但结果是一样的。
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 4.0f;
}
【问题讨论】:
-
请阅读此答案stackoverflow.com/questions/17229350/…。我想它会对你有所帮助。
-
我试过了,但还是不行。我设置了至少 20 像素,看看是否会出现问题,但单元格仍然没有间距。
标签: ios uicollectionview cellspacing