4
我有一个UITableView
,我想要它,所以当你点击单元格时,高度会动画到更高的高度(即:它会展开)。我该怎么做?如何动画UITableViewCell高度?
我有一个UITableView
,我想要它,所以当你点击单元格时,高度会动画到更高的高度(即:它会展开)。我该怎么做?如何动画UITableViewCell高度?
实际上很简单,为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;
}