草庐IT

ios - UICollectionView 在较小的设备上导致 "UICollectionViewFlowLayoutBreakForInvalidSizes"

coder 2023-09-10 原文

在 iPhone 6 Plus 上,collection view cells 很好,但是在 iPhone 5 等其他尺寸的设备上测试时,我被“

017-06-15 01:59:25.744 HyperTest[3865:8825385] The behavior of the UICollectionViewFlowLayout is not defined because: 2017-06-15 01:59:25.744 HyperTest[3865:8825385] 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. 2017-06-15 01:59:25.745 HyperTest[3865:8825385] The relevant UICollectionViewFlowLayout instance is , and it is attached to ; layer = ; contentOffset: {0, 0}; contentSize: {414, 219}> collection view layout: . 2017-06-15 01:59:25.745 HyperTest[3865:8825385] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

尤其是当我这样做的时候:

let layout = billFeedCollectionView.collectionViewLayout as? UICollectionViewFlowLayout // casting is required because UICollectionViewLayout doesn't offer header pin. It's feature of UICollectionViewFlowLayout
    layout?.sectionHeadersPinToVisibleBounds = true
    layout?.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize

无论如何,我能解决这个问题吗?我需要确保单元可缩放并适合所有设备。

最佳答案

通过确认来自您类(class)的 UICollectionViewDelegate。委托(delegate)方法 sizeForItemAtIndexPath 将从 UICollectionViewDelegateFlowLayout 调用,这将在您的类中调用,现在您可以返回 UICollectionViewCell 的大小。

这对我有用

方法:

collectionView.delegate = self

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
     return CGSizeMake(collectionView.frame.size.width, collectionView.frame.size.height)
}

关于ios - UICollectionView 在较小的设备上导致 "UICollectionViewFlowLayoutBreakForInvalidSizes",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44559745/

有关ios - UICollectionView 在较小的设备上导致 "UICollectionViewFlowLayoutBreakForInvalidSizes"的更多相关文章

随机推荐