【问题标题】:How to move certain cells down in UICollectionView如何在 UICollectionView 中向下移动某些单元格
【发布时间】:2013-09-30 14:30:43
【问题描述】:

我想将某些UICollectionViewCells 向下移动一个固定高度。我尝试覆盖-layoutAttributesForElementsInRect: 并更新UICollectionViewLayoutAttributes 返回的数组中UICollectionViewLayoutAttributescenter [super layoutAttributesForElementsInRect:rect],但不知何故有些单元格以这种方式丢失了。我需要覆盖其他东西吗?

【问题讨论】:

  • 你能解决吗?试过我的解决方案了吗?

标签: iphone ios objective-c ipad uicollectionview


【解决方案1】:

实现 UICollectionView 的这个委托方法,您可以更改特定单元格的框架:

-(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath

【讨论】:

    【解决方案2】:

    尝试实现这个委托。它对我有用:

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
       if (indexPath.item == ....)
       {
          return newSize;
       }
       else
          return oldSize;
    }
    

    如果你想让这个动作增加动画单元格的高度,你可以调用这个代理

    [_yourCollectionView performBatchUpdates:nil completion:nil];
    

    因此您可以在触发某些操作时刷新您的单元格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多