什么时候UITableView内容大小更新行插入/删除动画 [英] When does UITableView content size update with row insert/delete animation

查看:127
本文介绍了什么时候UITableView内容大小更新行插入/删除动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,当UITableView的内容大小更新后,做一个插入/删除动画调用。我认为这将是像大多数[UIView动画...]块,因为帧大小/内容大小将立即更新,即使动画还没有完成,但它似乎并不是这样的方式。任何想法?

解决方案

不幸的是,我在添加/删除行时找不到更新contentSize的好方法从UITableView中,但我发现一种方法来计算如果你知道你正在添加/删除单元格的索引路径。



使用索引修改行的路径,可以使用tableView:heightForRowAtIndexPath:方法计算各个单元格的高度,并将其添加到表视图的当前内容大小高度。下面是一个例子,如果你只添加一行:

  [self.tableView insertRowsAtIndexPaths:@ [indexPathOfNewRow] withRowAnimation:UITableViewRowAnimationAutomatic] ; 
CGFloat newCellHeight = [self tableView:self.tableView heightForRowAtIndexPath:indexPathOfNewRow];
CGFloat newContentSizeHeight = self.tableView.contentSize.height + newCellHeight


I am curious when the UITableView's content size is updated after doing an insert/delete animation call. I figured it would be like most [UIView animation...] blocks in that the frame size/content size would be updated immediately even though the animation hasnt completed, but it does not seem to be that way. Any ideas?

解决方案

Unfortunately, I haven't been able to find a good way to update the contentSize when adding/deleting rows from a UITableView either, but I did find a way to calculate what it will be if you know the index paths of the cells you are adding/removing.

Using the index path of the modified rows, you can calculate the heights of the respective cells with the tableView:heightForRowAtIndexPath: method and add it to the current content size height of the table view. Here's an example if you're adding just one row:

[self.tableView insertRowsAtIndexPaths:@[indexPathOfNewRow] withRowAnimation:UITableViewRowAnimationAutomatic];
CGFloat newCellHeight = [self tableView:self.tableView heightForRowAtIndexPath:indexPathOfNewRow];
CGFloat newContentSizeHeight = self.tableView.contentSize.height + newCellHeight

这篇关于什么时候UITableView内容大小更新行插入/删除动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆