选择时,您可以为 UITableViewCell 上的高度变化设置动画吗? [英] Can you animate a height change on a UITableViewCell when selected?

查看:39
本文介绍了选择时,您可以为 UITableViewCell 上的高度变化设置动画吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 iPhone 应用程序中使用了 UITableView,并且我有一个属于某个组的人员列表.我希望这样当用户单击特定的人(从而选择单元格)时,单元格的高度会增加以显示多个用于编辑该人属性的 UI 控件.

I'm using a UITableView in my iPhone app, and I have a list of people that belong to a group. I would like it so that when the user clicks on a particular person (thus selecting the cell), the cell grows in height to display several UI controls for editing the properties of that person.

这可能吗?

推荐答案

我发现了一个非常简单的解决方案,作为我正在研究的 UITableView 的副作用.....

I found a REALLY SIMPLE solution to this as a side-effect to a UITableView I was working on.....

通过tableView:heightForRowAtIndexPath:将单元格高度存储在一个通常报告原始高度的变量中,然后当你想要动画高度变化时,只需更改变量的值并调用它...

Store the cell height in a variable that reports the original height normally via the tableView: heightForRowAtIndexPath:, then when you want to animate a height change, simply change the value of the variable and call this...

[tableView beginUpdates];
[tableView endUpdates];

你会发现它没有完全重新加载,但足以让 UITableView 知道它必须重绘单元格,获取单元格的新高度值......并猜测什么?它为您带来变化.甜.

You will find it doesn't do a full reload but is enough for the UITableView to know it has to redraw the cells, grabbing the new height value for the cell.... and guess what? It ANIMATES the change for you. Sweet.

我的博客上有更详细的解释和完整的代码示例... 动画 UITableView 单元格高度变化

I have a more detailed explanation and full code samples on my blog... Animate UITableView Cell Height Change

这篇关于选择时,您可以为 UITableViewCell 上的高度变化设置动画吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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