我有一个UITableView,其中一些行使用indentationLevel缩进。单元格具有UITableViewCellStyleValue1样式,因此我得到textLabel缩进但不是detailTextLabel。有时我想更改行的缩进,以便文本向左或向右移动。设置indentationLevel是有效的,但是文本突然跳起来:我怎样才能让它平滑动画?
答案 0 :(得分:1)
这样做 - 通过indentDelta更改缩进:
CGRect frame = cell.textLabel.frame;
frame.origin.x += indentDelta * cell.indentationWidth;
[UIView animateWithDuration:0.5f animations:^{
cell.textLabel.frame = frame;
} completion:^(BOOL finished){
cell.indentationLevel = cell.indentationLevel + indentDelta;
}];
首先将标签平滑地滚动到我想要的位置,然后使用正确的截断重新绘制行,并使用indentationLevel保持正确,以便在重新生成时正确绘制,例如,如果点击选择。
答案 1 :(得分:0)
因为UITableViewCell是UIView的子类,所以您可以尝试使用UIView's animation methods。
[UIView animateWithDuration:0.5f animations:^{
cell.indentationLevel = 2;
}];
如果这不起作用,您可能需要调整动画块内视图框架的origin.x字段。