我有一个集合视图,它本身是委托和数据源,并且布局定义如下:
- (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;
}