since iOS 14, UICollectionView's scrollToItem(at:at:animated:) method is broken under certain circumstances.
The setup
I'm using UICollectionViewCompositionalLayout to define two sections. The first section scrolls horizontally and also has a section header configured:
Code Block swift section.orthogonalScrollingBehavior = .paging let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(44)), elementKind: "header", alignment: .top) section.boundarySupplementaryItems = [header]
The behavior
Depending on different settings for section.orthogonalScrollingBehavior I observe the following:
scrollToItem
does not work if orthogonalScrollingBehavior is .paging, .groupPaging, .groupPagingCentered ❌
does work if orthogonalScrollingBehavior is .continuous or .continuousGroupLeadingBoundary ✅
does work if I don't add the header to the section ✅
does work if the header's height is .absolute(0) ✅
does work if the header's alignment is .bottom (i.e. if the section's boundarySupplementaryItem is a footer instead of a header) ✅
Anyone any ideas what might cause this? There's no problem on iOS 13.x.