我正在使用UICollectionView
. 当用户旋转设备时,我对UICollectionView
内部执行更新
func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
我以UIViewController
模态方式呈现这个并UICollectionView
占据了全屏。在 内viewDidLoad
,我将流布局创建为:
let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = .horizontal
flowLayout.minimumInteritemSpacing = 0
flowLayout.minimumLineSpacing = 0
photosCollectionView.isPagingEnabled = true
photosCollectionView.setCollectionViewLayout(flowLayout, animated: true)
我的尺寸也为:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return photosCollectionView.frame.size
}
当我旋转我的设备时,viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
永远不会调用,这会导致UICollectionViewLayout
不更新。当我旋转设备时,我确实收到了消息:
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.
我在网上阅读过,我可以添加:
self.automaticallyAdjustsScrollViewInsets = false
到UIViewController
,但这并没有影响。没有内容或部分插图UICollectionView
。
我也有super.viewWillTransition
函数内的调用。任何人都可以帮助我解决可能导致此问题的原因吗?