I have a project that has UICollectionView
which needs to have paging. I have set horizontal scroll
and paging enabled
. MinimumInteritemSpacing
is 0. I need the cells to be the size of the collection view so I have:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return collectionView.frame.size
}
This sizes the cells properly for both portrait and landscape, but the offset on orientation change is wrong and two cells will be displayed at the same time. What is a good approach to be able to see the same cell on orientation change and for it to be taking up the whole collection view?
I have tried implementing collectionView(_:targetContentOffsetForProposedContentOffset:)
This will fix the issue if you stay on one screen, but going to another screen, rotating and going back to the collection view screen will have a bug - there will be again two partially visible cells and the offset will not be the wanted one. This is why I guess there should be another solution to this issue.