[英]TableView Animation
我有一个带有一些行的UITableView。 我希望所选的单元格始终位于UITableView的最顶部,并且所选单元格之后的单元格应动画到底部。
为了动画,我使用了以下代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
CGFloat height = 44.0f; //cell height
tableView.contentInset = UIEdgeInsetsMake(0, 0, height * indexPath.row, 0);
[tableView setContentOffset:CGPointMake(0, (indexPath.row * height) )
animated:YES]; //set the selected cell to top
}
我的问题是在选定的单元格到达底部后如何为单元格设置动画?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
// I will assume you have your tableView's data stored in an array: _dataArray
[_tableView beginUpdates];
[_dataArray insertObject:[_dataArray objectAtIndex:indexPath.row] atIndex:0];
[_dataArray removeObjectAtIndex:([_dataArray count]-1)];
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.