On Apple\'s Photo\'s App, if you rotate device while scroll to an arbitrary offset, same cell that was in the center beforehand would end u
Accepted answer did not work for me.
In my case neither method of UICollectionViewDelegate
collectionView(_:targetContentOffsetForProposedContentOffset:)
nor the method of UICollectionViewLayout was called
targetContentOffset(forProposedContentOffset:)
Instead, I inherited from UICollectionView and overrode layoutSubviews method:
class CollectionView: UICollectionView {
override func layoutSubviews() {
let old = contentOffset
super.layoutSubviews()
contentOffset = old
}
}
This may cause some side effects, so check it carefully before use in production