【问题标题】:How to move certain cells down in UICollectionView如何在 UICollectionView 中向下移动某些单元格
【发布时间】:2013-09-30 14:30:43
【问题描述】:
我想将某些UICollectionViewCells 向下移动一个固定高度。我尝试覆盖-layoutAttributesForElementsInRect: 并更新UICollectionViewLayoutAttributes 返回的数组中UICollectionViewLayoutAttributes 的center [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];
因此您可以在触发某些操作时刷新您的单元格。