Hello guys! I'm having this weird issue with a basic compositional layout (full screen cell with horizotal swiping), on a collection view: whenever I rotate the device, it's showing the wrong cell.
I think this is a problem of the content offset, because it's always jumping to the previous image (2nd to 1st, 3rd to 2nd, etc.), and this is even before the rotation started (I tried setting the cell manually in viewWillTransition, but it also jumps). And when i come back to portrait, it returns to the "original" image.
Here is a gif with the slow animation: https://gifyu.com/image/S3M3d. Note that on the video the cell is changing from 2nd to 1st, but if I'm on the 3rd cell, it changes to the 2nd one. So it seems it's always to the previous one.
This is the layout definition:
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .fractionalHeight(1)
)
let layoutItem = NSCollectionLayoutItem(layoutSize: itemSize)
layoutItem.contentInsets = .zero
layoutItem.edgeSpacing = NSCollectionLayoutEdgeSpacing(leading: .none , top: .none, trailing: .none, bottom: .none)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
let layoutGroup = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [layoutItem])
layoutGroup.interItemSpacing = .fixed(0)
let layoutSection = NSCollectionLayoutSection(group: layoutGroup)
layoutSection.interGroupSpacing = 0
layoutSection.orthogonalScrollingBehavior = .groupPaging
let collectionViewLayout = UICollectionViewCompositionalLayout(section: layoutSection)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.backgroundColor = .clear
collectionView.bounces = false
collectionView.isPagingEnabled = true
collectionView.showsHorizontalScrollIndicator = false
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(CustomCell.self, forCellWithReuseIdentifier: "...")
I've tried everything (removed every spacing, inset, and all that I could find), but I can't make it work. Any ideas? It's been driving me crazy. Thanks in advance.