UICollectionView OrthogonalsCrollingBehavior gropavepingcented错误的行为
因此,我有一个带有以下布局的收集视图,
private static func createChannelsCompositionalLayout() -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(0.45))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
item.contentInsets.top = 5
item.contentInsets.bottom = 5
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.87), heightDimension: .fractionalHeight(1))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitem: item, count: 2)
group.contentInsets.trailing = 10
group.contentInsets.leading = 10
group.contentInsets.bottom = 10
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .groupPagingCentered
let layout = UICollectionViewCompositionalLayout(section: section)
return layout
}
基本上它可以水平滚动,每组垂直显示两个项目。 如果物品数量均匀,则可以正常工作;但是,如果项目数是奇数的,则当您滚动到最后一个组(其中包含1个项目而不是2个)时,它不会像2个项目那样完美地拍摄。它将更靠近屏幕的边缘,第二组将显示出不可取的第二组。 这是一个错误,还是我可以更改代码的东西?
我尝试使用插图和分数玩一些,但没有快乐。我还尝试在该部分中添加ContentInset,但这也无济于事。
So I have a collection view with the following layout
private static func createChannelsCompositionalLayout() -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(0.45))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
item.contentInsets.top = 5
item.contentInsets.bottom = 5
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.87), heightDimension: .fractionalHeight(1))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitem: item, count: 2)
group.contentInsets.trailing = 10
group.contentInsets.leading = 10
group.contentInsets.bottom = 10
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .groupPagingCentered
let layout = UICollectionViewCompositionalLayout(section: section)
return layout
}
Basically it scrolls horizontally with two items displayed vertically per group.
It works fine if the number of items is even; however if the number of items is odd, when you scroll to the last group (which would contain 1 item instead of 2), it wouldn't snap perfectly like it does with 2 items. It will be closer to the screen's edge and a bigger portion of the second to last group will be shown which is not desirable.
Is that a bug or is there something I could change in my code?
I tried playing a little bit with the insets and fractions but no joy. I also tried adding a contentInset to the section but that didn't help either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论