czl0325 / ZLCollectionView

为应对类似淘宝首页,京东首页,国美首页等复杂布局而写的Collectionview。基于UICollectionView实现,目前支持标签布局,列布局,百分比布局,定位布局,填充式布局,瀑布流布局等。支持纵向布局和横向布局,可以根据不同的section设置不同的布局,支持拖动cell,头部悬浮,设置section背景色和自定义section背景view,向自定义背景view传递自定义方法。功能强大,超过Android的recyclerview,实现了电影选座等高难度的布局。
MIT License
1.16k stars 166 forks source link

ClosedLayout类型下,宽度偶尔计算不正确,导致item的错位 #64

Closed tang786472181 closed 1 year ago

tang786472181 commented 1 year ago
插入feedbanner 插入后 1条数据 items.count=1
2022-12-30 10:03:30.529360+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 8}, {-20, 258.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0deb00b5> {length = 2, path = 0 - 0}
2022-12-30 10:03:30.529772+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 8}, {-20, 258.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0deb00b5> {length = 2, path = 0 - 0}
2022-12-30 10:03:30.529843+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 8}, {-20, 194}}, indexPath=<NSIndexPath: 0x94a9be3c0ceb00b5> {length = 2, path = 0 - 1}
2022-12-30 10:03:30.529895+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 212}, {-20, 205.5}}, indexPath=<NSIndexPath: 0x94a9be3c0feb00b5> {length = 2, path = 0 - 2}
2022-12-30 10:03:30.529979+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 276.66666666666669}, {-20, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c0eeb00b5> {length = 2, path = 0 - 3}
2022-12-30 10:03:30.530091+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 427.5}, {-20, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c09eb00b5> {length = 2, path = 0 - 4}
2022-12-30 10:03:30.530163+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 464.16666666666669}, {-20, 205.5}}, indexPath=<NSIndexPath: 0x94a9be3c08eb00b5> {length = 2, path = 0 - 5}
2022-12-30 10:03:30.530221+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 679.66666666666674}, {-20, 295}}, indexPath=<NSIndexPath: 0x94a9be3c0beb00b5> {length = 2, path = 0 - 6}
2022-12-30 10:03:30.530267+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 756.16666666666674}, {-20, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0aeb00b5> {length = 2, path = 0 - 7}
2022-12-30 10:03:30.530338+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 984.66666666666674}, {-20, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c05eb00b5> {length = 2, path = 0 - 8}
2022-12-30 10:03:30.530398+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 1084.8333333333335}, {-20, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c04eb00b5> {length = 2, path = 0 - 9}
插入feedbanner 开始展示item frame={{4, 1272.3333333333335}, {-20, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c07eb00b5> {length = 2, path = 0 - 10}
插入feedbanner feed流首页数据回来了,先移除除了feeds之外的所有数据 items.count=11
插入feedbanner feed流首页数据回来了,移除后的所有数据 items.count=11
2022-12-30 10:03:31.748776+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 8}, {194, 258.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0deb00b5> {length = 2, path = 0 - 0}
2022-12-30 10:03:31.748844+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 8}, {194, 194}}, indexPath=<NSIndexPath: 0x94a9be3c0ceb00b5> {length = 2, path = 0 - 1}
2022-12-30 10:03:31.748892+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 212}, {194, 205.5}}, indexPath=<NSIndexPath: 0x94a9be3c0feb00b5> {length = 2, path = 0 - 2}
2022-12-30 10:03:31.748932+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 276.66666666666669}, {194, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c0eeb00b5> {length = 2, path = 0 - 3}
2022-12-30 10:03:31.748970+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 427.5}, {194, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c09eb00b5> {length = 2, path = 0 - 4}
2022-12-30 10:03:31.749011+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 464.16666666666669}, {194, 205.5}}, indexPath=<NSIndexPath: 0x94a9be3c08eb00b5> {length = 2, path = 0 - 5}
2022-12-30 10:03:31.749047+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 679.66666666666674}, {194, 295}}, indexPath=<NSIndexPath: 0x94a9be3c0beb00b5> {length = 2, path = 0 - 6}
2022-12-30 10:03:31.749095+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 756.16666666666674}, {194, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0aeb00b5> {length = 2, path = 0 - 7}
2022-12-30 10:03:31.749133+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 984.66666666666674}, {194, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c05eb00b5> {length = 2, path = 0 - 8}
2022-12-30 10:03:31.749363+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 1084.8333333333335}, {194, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c04eb00b5> {length = 2, path = 0 - 9}
2022-12-30 10:03:31.749401+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 1272.3333333333335}, {194, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c07eb00b5> {length = 2, path = 0 - 10}

插入feedbanner 插入后 1条数据 items.count=1
2022-12-30 10:07:23.287100+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 8}, {-20, 258.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0deb00b5> {length = 2, path = 0 - 0}
2022-12-30 10:07:23.287369+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 8}, {-20, 258.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0deb00b5> {length = 2, path = 0 - 0}
2022-12-30 10:07:23.287447+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 212}, {-20, 205.5}}, indexPath=<NSIndexPath: 0x94a9be3c0feb00b5> {length = 2, path = 0 - 2}
2022-12-30 10:07:23.287476+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 276.66666666666669}, {-20, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c0eeb00b5> {length = 2, path = 0 - 3}
2022-12-30 10:07:23.287506+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 427.5}, {-20, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c09eb00b5> {length = 2, path = 0 - 4}
2022-12-30 10:07:23.287535+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 464.16666666666669}, {-20, 205.5}}, indexPath=<NSIndexPath: 0x94a9be3c08eb00b5> {length = 2, path = 0 - 5}
2022-12-30 10:07:23.287565+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 679.66666666666674}, {-20, 295}}, indexPath=<NSIndexPath: 0x94a9be3c0beb00b5> {length = 2, path = 0 - 6}
2022-12-30 10:07:23.287594+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 756.16666666666674}, {-20, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0aeb00b5> {length = 2, path = 0 - 7}
2022-12-30 10:07:23.287622+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 984.66666666666674}, {-20, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c05eb00b5> {length = 2, path = 0 - 8}
2022-12-30 10:07:23.287649+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 1084.8333333333335}, {-20, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c04eb00b5> {length = 2, path = 0 - 9}
2022-12-30 10:07:23.288965+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{4, 1272.3333333333335}, {-20, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c07eb00b5> {length = 2, path = 0 - 10}
插入feedbanner feed流首页数据回来了,先移除除了feeds之外的所有数据 items.count=11
插入feedbanner feed流首页数据回来了,移除后的所有数据 items.count=11
2022-12-30 10:07:23.762477+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 8}, {194, 258.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0deb00b5> {length = 2, path = 0 - 0}
2022-12-30 10:07:23.762655+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 8}, {194, 194}}, indexPath=<NSIndexPath: 0x94a9be3c0ceb00b5> {length = 2, path = 0 - 1}
2022-12-30 10:07:23.762760+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 212}, {194, 205.5}}, indexPath=<NSIndexPath: 0x94a9be3c0feb00b5> {length = 2, path = 0 - 2}
2022-12-30 10:07:23.762833+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 276.66666666666669}, {194, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c0eeb00b5> {length = 2, path = 0 - 3}
2022-12-30 10:07:23.762908+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 427.5}, {194, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c09eb00b5> {length = 2, path = 0 - 4}
2022-12-30 10:07:23.763017+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 464.16666666666669}, {194, 205.5}}, indexPath=<NSIndexPath: 0x94a9be3c08eb00b5> {length = 2, path = 0 - 5}
2022-12-30 10:07:23.763087+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 679.66666666666674}, {194, 295}}, indexPath=<NSIndexPath: 0x94a9be3c0beb00b5> {length = 2, path = 0 - 6}
2022-12-30 10:07:23.763180+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 756.16666666666674}, {194, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c0aeb00b5> {length = 2, path = 0 - 7}
2022-12-30 10:07:23.763399+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{16, 984.66666666666674}, {194, 318.66666666666669}}, indexPath=<NSIndexPath: 0x94a9be3c05eb00b5> {length = 2, path = 0 - 8}
2022-12-30 10:07:23.763571+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 1084.8333333333335}, {194, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c04eb00b5> {length = 2, path = 0 - 9}
2022-12-30 10:07:23.763651+0800 mixc[2060:6927440] 插入feedbanner 开始展示item frame={{218, 1272.3333333333335}, {194, 177.5}}, indexPath=<NSIndexPath: 0x94a9be3c07eb00b5> {length = 2, path = 0 - 10}

看打印日志,宽度偶尔计算为负数

打印位置 image

tang786472181 commented 1 year ago

CGFloat totalWidth = self.collectionView.frame.size.width; 实际上这个时候totalWidth为0,所以是否加一个判断过滤这一次的布局计算呀