如何为 UITableViewCell 高度设置动画? [复制]
Posted
技术标签:
【中文标题】如何为 UITableViewCell 高度设置动画? [复制]【英文标题】:How to animate UITableViewCell height? [duplicate] 【发布时间】:2013-01-06 04:46:20 【问题描述】:我有一个UITableView
,我想要它,以便当您点击单元格时,高度会动画到更高的高度(即:它会扩展)。我该怎么做?
【问题讨论】:
【参考方案1】:实际上很简单,为NSIndexPath
创建一个实例变量,我称之为selectedIndexPath
。然后,您需要做的就是在heightForRowAtIndexPath
中创建一个条件,以独立于其他单元格调整此特定单元格的高度。
然后在didSelectRowAtIndexPath
中将选定的索引路径iVar 设置为选定单元格的索引路径,并在表格上调用开始/结束更新。单元格会自动展开并带有漂亮的动画。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
selectedIndexPath = indexPath;
[self.tableView beginUpdates];
[self.tableView endUpdates];
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
if ([indexPath compare:selectedIndexPath] == NSOrderedSame)
return 80;
return 40;
【讨论】:
以上是关于如何为 UITableViewCell 高度设置动画? [复制]的主要内容,如果未能解决你的问题,请参考以下文章
如何为 UITableViewCell 的 ImageView 设置固定大小?