iPhone - UITableViewCell高度变化的平滑动画,包括内容更新 [英] iPhone - Smooth animation for UITableViewCell height change including content update

查看:83
本文介绍了iPhone - UITableViewCell高度变化的平滑动画,包括内容更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

你能在UITableViewCell上选择高度变化吗?

我有一个表格视图,你可以在其中点击一个swich到一个单元格,表视图的许多单元格可能会改变它们的高度。计算哪些单元格会改变它们的大小有点复杂,所以我不想调用两次相同的代码。

I have a table view into which where you click on a swich into a cell, many cells of the table view may change their height. It's a little bit complicated to compute which cells will change their size, so I'd like not to call twice the same code.

我有 heightForRowAtIndexPath 方法(这是一个复杂的方法)。

I have a heightForRowAtIndexPath method (this is the complicated one).

有没有办法动画细胞增长或减少功能而不会影响那个不会改变吗?

Is there a way to animate the cell grow or reduce feature without impacting the one that does not change ?

我试过 UIView 动画,动画部分的reloadData,......但我没找到任何顺利的东西。
我试图抓住每个必须更改的单元格,并在每个单元格上调用带动画的reloadData。它接近工作,但细胞一个接一个地更新。正如我之前所说,我不想这样做,因为我必须调用两次heightForRowAtIndexPath方法。

I've tried UIView Animations, reloadData for sections with animation, ... but I didn't find anything smooth. I've tried to catch each cell that will have to change and call a reloadData with animation on each cell. It's near to work but the cells are updating one after the other. And as I said before, I don't want to do that because I must call twice the heightForRowAtIndexPath method.

我想要的是可以为每个单元格设置动画的内容它的高度变化,像增长或减少运动,而不是褪色。

What I'd like is something that can animated each cell that has a changing height with somthing like a grow or reduce movement, and not a fade one.

你知道这样做的方法吗?
还有一件事,当大小改变时(单位添加了一些文字,背面颜色变化等等),单元格的内容会发生一些变化。

Do you know a way to do that ? One more thing, the content of the cell is changing a little bit when size change (some text added, back color changing, and things like that)

推荐答案

UITableView有一个巧妙的技巧来动画单元格高度的变化:如果你向表格视图发送一个空的更新块,它将不会插入或删除任何单元格,但它仍然会重新计算单元格整个桌子的高度。所以即使这段代码看起来很奇怪,它应该这样做:

UITableView has a neat trick to animate changes in cell heights: if you send an empty updates block to the table view, it won't insert or delete any cells, but it will still recalculate cell heights for the entire table. So even though this piece of code looks weird, it should do it:

[tableView beginUpdates];
[tableView endUpdates];

如果您想更改更新的单元格的内容,则必须添加一个或多个调用到 reloadRowsAtIndexPaths:withRowAnimation:到更新块当然。

If you want to change the contents of the updated cells, too, you must add one or more calls to reloadRowsAtIndexPaths:withRowAnimation: to the updates block, of course.

这篇关于iPhone - UITableViewCell高度变化的平滑动画,包括内容更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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