For given layout, UICollectionView always returns content size which is equal to UICollectionView size, even if items go beyond the UICollectionView.
private lazy var layout: UICollectionViewCompositionalLayout = {
let margin = 8.0
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0)
)
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(
widthDimension: .estimated(56),
heightDimension: .fractionalHeight(1.0)
)
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: .zero, leading: margin, bottom: .zero, trailing: margin)
section.orthogonalScrollingBehavior = .continuous
return UICollectionViewCompositionalLayout(section: section)
}()
Also I suspect, because of that I cannot programatically scroll to items beyond the screen.
What can be wrong here?
I tried to change widthDimension of item and the group, contentInsets, but it didn’t work.
UPDATE
The correct way to to this was to use:
NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitem: item, count: 1)
and
section.orthogonalScrollingBehavior = .continuousGroupLeadingBoundary
2
Answers
Try to change the size of the group.
Instead of this:
Try:
I think the problem is that you didn’t set the height for the group.
Try to use:
section.orthogonalScrollingBehavior = .paging