动画UICollectionView单元格大小更改并重新定位周围的单元格 [英] Animate UICollectionView cell size change and reposition surrounding cells

查看:143
本文介绍了动画UICollectionView单元格大小更改并重新定位周围的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:

为单元格高度的变化设置动画并重新定位周围的单元格。

To animate the change of a cell's height and reposition surrounding cells.

场景:

集合视图中的某些单元格会加载远程图像。最初,这些单元格的大小是静态的,并显示了活动指示符。加载图像后,将其添加到其单元格中,并更改单元格的高度以适合照片。

Some cells in a collection view load remote images. Initially, those cells are sized statically and an activity indicator is shown. After an image is loaded, it is added to its cell and the cell's height is changed to fit the photo.

注意:

我使用 animateWithDuration 为单元格的帧更改设置动画。这种方法很好,除了增加的单元格大小与下面的单元格重叠。在调整目标单元格大小并更新 sizeForItemAtIndexPath 返回的大小后,我盲目地尝试调用 collectionView.collectionViewLayout invalidateLayout 成功。

I am animating the cell's frame change with animateWithDuration. This works fine, except an increased cell size has it overlapping the cells below. I've blindly tried calling collectionView.collectionViewLayout invalidateLayout after resizing the target cell and updating the size returned by sizeForItemAtIndexPath with no success.

有什么建议吗?谢谢!

示例代码:

https://github.com/juzzin/ResizeUICollectionViewCell/blob/master/ResizeUICollectionViewCell/FLOViewController.m

推荐答案

基本上你需要做三个步骤

Basically you need to do three steps

1.验证collectionViewLayout

1.invalidate the collectionViewLayout

2.执行批量更新:

 ...
 //invalidate layout
[collectionView performBatchUpdates:^{
    // make your cell at indexPath return a new size
} completion:^(BOOL finished) {

}];

3.在 sizeForItemAtIndexpath 返回新尺寸

这篇关于动画UICollectionView单元格大小更改并重新定位周围的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆