UICollectionView 布局警告

UICollectionView Layout Warnings

在格式化我的主单元格以进行水平滚动后,我一直收到一条警告,向整个控制台发送垃圾邮件,这让我很烦。

我已经尝试过更改约束和单元格大小,但警告总是以某种方式出现。

在我的 feedCell class:

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 class 中,我正在使用由以下定义的水平滚动单元格:

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。这似乎为我解决了这个问题。