I have made an Onboarding View using a collectionView
with 2 items.
When I change device orientation from landscape to portrait the second item being animated and visible within the first item screen borders.
You can see the problem here: https://cln.sh/sgypvH
How to fix the animation so when switching from landscape to portrait I could see only the first item content with a white background on the screen?
Here is my code for collectionViewLayout:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView.frame.width, height: collectionView.frame.height)
}
Here is the code for willTransition
:
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
collectionView.collectionViewLayout.invalidateLayout()
let indexPath = IndexPath(item: self.currentPage, section: 0)
DispatchQueue.main.async {
self.collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
}
}
Please let me know if you need anything extra to help me to solve the issue. Thank you!