I'm creating a full screen image gallery using a UICollectionView
. When the user rotates the device, I perform updates to the UICollectionView
within
func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
I present this UIViewController
modally and have a UICollectionView
taking up the full screen. Within viewDidLoad
, I create the flow layout as:
let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = .horizontal
flowLayout.minimumInteritemSpacing = 0
flowLayout.minimumLineSpacing = 0
photosCollectionView.isPagingEnabled = true
photosCollectionView.setCollectionViewLayout(flowLayout, animated: true)
I also have the size as:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return photosCollectionView.frame.size
}
When I rotate my device, viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
is never called, which causes the UICollectionViewLayout
to not update. While I rotate the device, I do get the message:
The behavior of the UICollectionViewFlowLayout is not defined because: the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
I've read online that I can add:
self.automaticallyAdjustsScrollViewInsets = false
to the UIViewController
, but that had no affect. There are no content or section insets with the UICollectionView
.
I also have the super.viewWillTransition
called within the function as well. Can anyone assist me on what could be causing this issue?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…