UICollectionView 布局警告



格式化我的主要单元格以进行水平滚动后,我收到了一条警告,该警告会向整个控制台发送垃圾邮件,并且总体上让我很恼火。

我已经尝试更改约束和单元格大小,但无论如何总是出现警告。

在我的 feedCell 类中:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: frame.width, height: UIScreen.main.bounds.height / 3.5)
} //Sets each cell's frame
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return 0
} //Removes spacing between the cells

在我的 mainView 类中,我使用由以下定义的水平滚动单元格:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: view.frame.width, height: view.frame.height-60)
}

我还使用以下方法初始化我的菜单栏:

private func setupMenuBar() {
    navigationController?.hidesBarsOnSwipe = true
    view.addSubview(menuBar)
    view.addConstraintsWithFormat(format: "H:|[v0]|", views: menuBar)
    view.addConstraintsWithFormat(format: "V:|[v0(60)]", views: menuBar)
}

我还将导航栏设置为

navigationController?.hidesBarsOnSwipe = true

我的状态栏高度等于 20,但我认为这不是主要问题。

错误消息:

2019-06-14 19:38:55.755740+0300[71578:4274545] 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.
2019-06-14 19:38:55.756169+0300[71578:4274545] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7faba0f027d0>, and it is attached to <UICollectionView: 0x7faba1047000; frame = (0 0; 414 808); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600002e7c360>; layer = <CALayer: 0x600002074d40>; contentOffset: {0, -50}; contentSize: {0, 0}; adjustedContentInset: {50, 0, 34, 0}> collection view layout: <UICollectionViewFlowLayout: 0x7faba0f027d0>.
2019-06-14 19:38:55.756248+0300[71578:4274545] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

我已经解决了这个问题。如果有人也遇到此问题,请确保您没有使用UIScreen.main.bounds.height作为单元格大小,并将hidesBarsOnSwipe设置为true。这似乎为我解决了它。

最新更新