IOS遇到The behavior of the UICollectionViewFlowLayout is not defined because:

今天遇到用UICollectionView使用轮播图遇到的问题:

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.

打印如下:

2018-03-19 17:05:36.501659+0800 CheckBox[18573:492773] The behavior of the UICollectionViewFlowLayout is not defined because:
2018-03-19 17:05:36.501749+0800 CheckBox[18573:492773] 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.
2018-03-19 17:05:36.501940+0800 CheckBox[18573:492773] The relevant UICollectionViewFlowLayout instance is <CheckBox.WMRunScrollViewFlowLayout: 0x7f9fb83025e0>, and it is attached to <UICollectionView: 0x7f9fb686ca00; frame = (0 0; 375 200); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x6080002479e0>; layer = <CALayer: 0x608000428b80>; contentOffset: {112500, -24}; contentSize: {0, 0}; adjustedContentInset: {24, 0, 0, 0}> collection view layout: <CheckBox.WMRunScrollViewFlowLayout: 0x7f9fb83025e0>.
2018-03-19 17:05:36.502026+0800 CheckBox[18573:492773] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

解决办法:

override func viewDidLoad() {
        super.viewDidLoad()
        //自动计算滚动视图的内容边距
        self.automaticallyAdjustsScrollViewInsets = false //不自动计算
}

iOS11之后采用:

self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never;

关于UIScrollViewContentInsetAdjustmentBehavior的枚举类型

@available(iOS 11.0, *)
public enum UIScrollViewContentInsetAdjustmentBehavior : Int {


    case automatic // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable

    case scrollableAxes // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)

    case never // contentInset is not adjusted

    case always // contentInset is always adjusted by the scroll view's safeAreaInsets
}
  • automatic 与.scrollableAxes类似,但为了向后兼容,当滚动视图由视图控制器拥有时,也会调整顶部和底部contentInset,并且在导航控制器中自动调用ScrollViewInsets = YES,而不管滚动视图是否可滚动
  • scrollableAxes 调整可滚动轴的边缘(即,contentSize.width / height> frame.size.width / height或alwaysBounceHorizo​​ntal / Vertical = YES)
  • never 不调整cententinset
  • always 总是通过滚动视图的safeAreaInsets进行调整contentInset
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WMSmile

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值