ios – 滚动时奇怪的消失项目

前端之家收集整理的这篇文章主要介绍了ios – 滚动时奇怪的消失项目前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
预设,

我有collectionViewFlowLayout子类

  1. - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
  2. return YES;
  3. }
  4.  
  5. - (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
  6. NSArray *arr = [super layoutAttributesForElementsInRect:rect];
  7. BBLog(@"ARRA:%@",arr);
  8. for (UICollectionViewLayoutAttributes *attr in arr) {
  9. if (CGAffineTransformIsIdentity(attr.transform)) {
  10. attr.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);
  11. }
  12. }
  13.  
  14. return arr;
  15. }

CollectionView旋转到颠倒滚动

  1. self.collectionView.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);

但即使jus使用本机collectionViewFlowLayout而没有子类化,也就是git这个错误

问题

我在聊天中有两条消息,但是当在底部滚动(通常是顶部)消失第二项时.

给定rect的layoutAttributesForElementsInRect为两个indexPaths 0-0和0-1返回两个属性,但委托方法

  1. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

仅为indexPath 0-0调用

这里的图片


UPDATE
所以我发现它为什么会发生 – 这个行代码

  1. attr.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);

看看是否删除转换

解决方法

我不完全确定,但我认为,当你是UICollectionViewFlowLayout的子类时,你不应该直接修改属性,而是要复制属性,修改它并返回它.

顶级声明的简短说明:
您必须继承UICollectionViewFlowDelegate(UICollectionViewDelegateFlowLayout的父级),然后创建自己的属性并根据需要修改它们,但这需要实现更多的自定义逻辑.

另请查看您是否在控制台中收到任何错误或警告.

看看这个问题:Warning: UICollectionViewFlowLayout has cached frame mismatch for index path ‘abc’

希望我至少有一点帮助.

猜你在找的iOS相关文章