UICollection View 导致“UICollectionViewFlowLayoutBreakForInvalidSizes"在较小的设备上 [英] UICollection View causes "UICollectionViewFlowLayoutBreakForInvalidSizes" on smaller devices

查看:30
本文介绍了UICollection View 导致“UICollectionViewFlowLayoutBreakForInvalidSizes"在较小的设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iPhone 6 Plus 上,集合视图单元格很好,但是在 iPhone 5 等其他尺寸的设备上进行测试时,我被

On an iPhone 6 Plus, the collection view cells are fine, but when testing on another device size like the iPhone 5, i'm bombarded with "

017-06-15 01:59:25.744 HyperTest[3865:8825385] 未定义 UICollectionViewFlowLayout 的行为,因为:2017-06-15 01:59:25.744 HyperTest[3865:8825385] 项目宽度必须小于 UICollectionView 的宽度减去部分 insets left 和 right 值,减去 content insets left 和 right 值.2017-06-15 01:59:25.745 HyperTest[3865:8825385] 相关的 UICollectionViewFlowLayout 实例是 ,它附加到 ;层 = ;内容偏移量:{0, 0};contentSize: {414, 219}> 集合视图布局: .2017-06-15 01:59:25.745 HyperTest[3865:8825385] 在 UICollectionViewFlowLayoutBreakForInvalidSizes 处创建一个符号断点以在调试器中捕获它.

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

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

anyway, I can resolve this problem? I need to ensure that the cell scales and fits all devices.

推荐答案

通过从您的班级中确认 UICollectionViewDelegate.委托方法 sizeForItemAtIndexPath 将从 UICollectionViewDelegateFlowLayout 调用,这将在您的类中调用,现在您可以返回 UICollectionViewCell 的大小.

By confirming UICollectionViewDelegate from your class. The delegate method sizeForItemAtIndexPath will call from UICollectionViewDelegateFlowLayout and this will call in your class now you can return the size of 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)
}

这篇关于UICollection View 导致“UICollectionViewFlowLayoutBreakForInvalidSizes"在较小的设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆