Iphone 如何设置UITableViewCell高度的动画?
我有一个Iphone 如何设置UITableViewCell高度的动画?,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,我有一个UITableView,我想要它,这样当你点击单元格时,高度会动画化到一个更高的高度(即:它会展开)。我该怎么做呢?很简单,实际上,为nsindepath创建一个实例变量,我称之为selectedIndexPath。然后,您只需在heightforrowatinexpath中设置一个条件,以独立于其他单元格调整此特定单元格的高度 然后在didSelectRowAtIndexPath中,将所选索引路径iVar设置为所选单元格的索引路径,并调用表上的开始/结束更新。单元将自动展开,并显示一个
UITableView
,我想要它,这样当你点击单元格时,高度会动画化到一个更高的高度(即:它会展开)。我该怎么做呢?很简单,实际上,为nsindepath
创建一个实例变量,我称之为selectedIndexPath
。然后,您只需在heightforrowatinexpath
中设置一个条件,以独立于其他单元格调整此特定单元格的高度
然后在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;
}