繁体   English   中英

CollectionView 约束打破

[英]CollectionView Constraints breaking

我有一个collectionView,每个单元格都包含一个tableView。 灰色部分应该是collectionView。 在此处输入图像描述

但是当我运行应用程序时,我得到了这样的东西在此处输入图像描述

正如您可以清楚地看到,当前的表视图不遵守约束集。 我从控制台收到以下错误。

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.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7f80fd28e420>, and it 

is attached to <UICollectionView: 0x7f80fc08f800; frame = (0 114; 375 664); clipsToBounds = YES;
autoresize = RM+BM; gestureRecognizers = <NSArray: 0x600000d6c4b0>; layer = <CALayer: 0x6000003beee0>;
contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0};

layout: <UICollectionViewFlowLayout: 0x7f80fd28e420>; dataSource: <BizTiz.EventDetailController: 0x7f80fa0b7800>>.

Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

我该如何解决? 此外,当我将此 collectionView 推送到堆栈上时,会有一个小的滞后。 我猜这可能是由于先前的错误。

请在 UICollectionViewDelegateFlowLayout 中设置布局。

   func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: <cell_width>, height: <cell_height>)
    }

意识到我的错误......

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

我将高度设置为view.frame.height 我忘了减去顶部的额外高度。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM