2010-03-04 102 views
3

我有一个有很多行的UITableView。 它就像一个手风琴:http://docs.jquery.com/UI/Accordion 主细胞有子细胞,子细胞也有子细胞。所以这是一个三级的tableView。UITableView,如何捕捉动画结束?

那么,当用户选择一个单元格时,它会用行动画扩展(或折叠)子单元格。 但我需要设置tableView和scrollView的新大小。

我做的所有的东西在这个方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

问题: 当用户点击一个单元格,然后迅速点击一个子一个,第二个动画不这样做,那么的子单元等级2未被显示。但是尺寸已经确定(考虑到二级子单元已经显示)。

其实我玩的时间来处理这个......但它真的很烂。

这里是我的代码示例:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

// Checking with times (with 0,5 second interval in order to be sure that the previous animation is finished !) 

// Setting tableView & scollView heights 

[tableView beginUpdates]; 
if(position.isExpanded == YES) 
    [tableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationBottom]; 
else 
    [tableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop]; 
[tableView endUpdates]; 
} 

所以,我想抓住这个动画的结尾。 或者,玩一种信号量(但我只有一个过程...) 任何想法来解决这个问题?

请记住,在我的回复中,我真的是iPhone开发新手。

谢谢。

+0

重复的:http://stackoverflow.com/questions/7198633/how-can-i-tell-when-a-uitableview-animation-has-finished。那么,也许这是一个重复的,但它有一个工作答案的好处。 – fishinear 2013-07-29 16:28:44

+0

重复和答案是非常糟糕的。任何人都会遇到这个问题shoudl看看[UITableView动画回调](http://stackoverflow.com/questions/2802146/callback-for-uitableview-animations)和[UITableView行动画持续时间和完成回调](http:/ /stackoverflow.com/questions/3832474/uitableview-row-animation-duration-and-completion-callback) – River2202 2015-10-25 13:42:37

回答

0

该动画由类CAAnimation的实例控制。该类支持将被传递给此实例的代理的方法- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag。这些信息通常用于了解完成情况。

关于您的特殊要求,我会看看UIView类参考。有几个任务处理该视图的动画 - 这是基类UITableView。因此,对UIView有效的任何内容都应该对表格视图有效。

+9

你如何访问UITableView使用的CAAnimation实例? (为了设置代表) – Sorig 2011-03-20 21:11:29

+0

我想知道与上面评论相同的东西,任何人都知道答案? – ElasticThoughts 2012-10-19 13:34:25

0

另外:

你可以通过检查NSArray *animationKeys = [cell.layer animationKeys];并调用CAAnimation *animation = [cell.layer animationForKey:_a_key_];动画。之后,您可以设置委托并按上述方式获取完成情况。