我正在使用
我以模态方式呈现此
我也可以提供尺寸信息,它如下所示:
当我旋转我的设备时,从未调用
UICollectionView
创建全屏图库。当用户旋转设备时,我会在func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
中对UICollectionView
进行更新。我以模态方式呈现此
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
。有谁能帮助我解决这个问题?
UICollectionViewDelegate
函数collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
设置的。 - Mike Walker