【发布时间】:2019-11-07 20:55:34
【问题描述】:
我正在构建图像的集合视图(图库)。
布局是每行 3 个单元格。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width: CGFloat = (view.frame.width / 3) - 8
let height: CGFloat = width
return CGSize(width: width, height: height)
}
在我滚动到集合视图的底部之前,一切看起来都很棒。
到: super blown up picture, larger than the screen
我也收到此错误消息:
The behavior of the UICollectionViewFlowLayout is not defined because:
the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
Please check the values returned by the delegate.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fa97f708c70>, and it is attached to <UICollectionView: 0x7fa981022000; frame = (0 0; 414 896); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x6000019986f0>; layer = <CALayer: 0x6000017a8820>; contentOffset: {0, 498.33333333333331}; contentSize: {414, 1250}; adjustedContentInset: {88, 0, 34, 0}; layout: <UICollectionViewFlowLayout: 0x7fa97f708c70>; dataSource: <MarsRover.GalleryCollectionVC: 0x7fa97f50b610>>.
任何见解都会很棒,我也想把它变成无限滚动(api 预取),如果这意味着我可以忽略它,仅供参考。
【问题讨论】:
-
您是否尝试将您的收藏视图项目宽度计算更改为基于
collectionView而不是view.frame.width?比如:let width: CGFloat = (collectionView.frame.width / 3) - 8. -
谢谢,奥兰多,但我试过 view.bounds.width、view.frame.width、view.frame.size.width、cv.frame.size.width、cv.frame.width等等……
标签: ios swift uicollectionview uikit uicollectionviewdelegateflowlayout