I’ve horizontal UICollectionView with UICollectionViewCompositionalLayout and orthogonalScrollingBehavior = .groupPagingCentered, created like this:
non-public lazy var compositionalLayout = UICollectionViewCompositionalLayout(sectionProvider: { [weak self] (_: Int, _: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
guard let self else { return nil }
let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(self.cellWidth), heightDimension: .absolute(Const.Structure.itemSize.peak))
let merchandise = NSCollectionLayoutItem(layoutSize: itemSize)
merchandise.contentInsets = NSDirectionalEdgeInsets(high: 0, main: 0, backside: 0, trailing: 0)
let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(self.cellWidth), heightDimension: .absolute(Const.Structure.itemSize.peak))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
// group.contentInsets = NSDirectionalEdgeInsets(high: 0, main: 0, backside: 0, trailing: 0)
let part = NSCollectionLayoutSection(group: group)
part.orthogonalScrollingBehavior = .groupPagingCentered
part.visibleItemsInvalidationHandler = { [weak self] (_, _, _) in
guard let self else { return }
let heart = self.contentView.convert(self.collectionView.heart, to: self.collectionView)
guard let indexPath = self.collectionView.indexPathForItem(at: heart) else { return }
.... // Merchandise change handler
}
return part
})
I have to scroll for precise merchandise in my assortment view, so I’m making an attempt:
collectionView.scrollToItem(at: IndexPath(row: indexOfItem, part: 0), at: .centeredHorizontally, animated: false)
however it’s scrolling to incorrect merchandise.