[英]UICollectionView cell disappears when i scroll it
I have a collectionView whose scroll direction is horizontal.我有一个 collectionView,它的滚动方向是水平的。 It has only one line and its cell spacing is 16.0px.
它只有一行,单元格间距为 16.0px。 So i set its
collectionViewLayout
to a custom layout named UICollectionViewLeftAlignedLayout
subclass of UICollectionViewFlowLayout
:所以我设置其
collectionViewLayout
到名为自定义布局UICollectionViewLeftAlignedLayout
的子类UICollectionViewFlowLayout
:
UICollectionViewLeftAlignedLayout *layout = [[UICollectionViewLeftAlignedLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumInteritemSpacing = 16.0;
_myCollectionView.collectionViewLayout = layout;
_myCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
But when i scroll the collectionView, some cells of it disappeared.但是当我滚动 collectionView 时,它的一些单元格消失了。 So weird!
太奇怪了! I have tried every solution i can find from
google.com
, unfortunately did not work for me.我已经尝试了我可以从
google.com
找到的所有解决方案,但不幸的是对我不起作用。 I fix it and post the solution as a answer below.我修复它并将解决方案发布为下面的答案。
I have fixed it !我已经修好了!
I replace the custom UICollectionViewLeftAlignedLayout
with native UICollectionViewFlowLayout
just like this:我用原生
UICollectionViewFlowLayout
替换自定义UICollectionViewLeftAlignedLayout
就像这样:
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
_myCollectionView.collectionViewLayout = layout;
_myCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
And I set the cell spacing through storyboard(also you can set them through the layout's propery):我通过storyboard设置单元格间距(你也可以通过layout的property来设置):
Then i run the project again , the UICollectionViewCell DO NOT DISAPPEAR anymore.然后我再次运行该项目,UICollectionViewCell 不再消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.