我正在对我的一些图像使用集合视图。
每个图像应以屏幕大小显示,因此一个单元格具有屏幕宽度。这minimumInterItemSpacing
flowLayout 的值为 25。
所以现在的问题是,如果我滚动,集合视图不会滚动到下一个图像的开头,而是滚动到 interItemSpacing 的开头。
让我们举个例子:
Image/Cell width = 320
CollectionView's interItemSpacing = 25
如果我滚动一页,滚动视图内容偏移量为 320,而不是 345,这意味着第二个单元格不在屏幕中心。
如何解决这个问题?有什么建议么?
好吧,我发现有两个选项可以实现正确的滚动。
1. UICollectionViewController size
通过准确添加所需的值作为 interItemSpacing 来增加集合视图及其项目的大小。
这是一些代码:
- (void) setupCollectionView;
{
PSTCollectionViewFlowLayout *flowLayout = [[PSTCollectionViewFlowLayout alloc] init];
CGSize itemSize = self.view.bounds.size;
itemSize.width +=25;
[flowLayout setItemSize:itemSize];
[flowLayout setScrollDirection:PSTCollectionViewScrollDirectionHorizontal];
flowLayout.minimumInteritemSpacing = 0.0f;
flowLayout.minimumLineSpacing = 0.0f;
self.collectionView = [[PSTCollectionView alloc] initWithFrame:self.view.bounds
collectionViewLayout:flowLayout];
[self.collectionView registerClass:[AMDetailImageCell class]
forCellWithReuseIdentifier:AMDetailImageCellIdentifier];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.pagingEnabled = YES;
CGRect rectSize = self.view.bounds;
rectSize.size.width +=25;
self.collectionView.frame = rectSize;
[self.view addSubview:self.collectionView];
[self scrollToStartIndex];
}
2. SectionEdgeInset
使一页=一个部分并使用sectionEdgeInset会产生相同的解决方案,但-当然-并不总是一种选择!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)