如何判断UITableView动画何时完成? [英] How can I tell When a UITableView animation has finished?

查看:141
本文介绍了如何判断UITableView动画何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断[UITableView setEditing:YES animated:YES]何时完成?

How can I tell when [UITableView setEditing:YES animated:YES] has completed?

我不想提供任何上下文,因为我想避免任何人给我解决方法,我不感兴趣。

I don't want to give any context, because I want to avoid anybody giving me workarounds, which do not interest me.

我想要的是调用上面的内容,然后在动画完成时调用一个单独的函数。

What I want is to call the above, then have a separate function called when the animation is completed.

我编辑了帖子以提供上下文和一些解决方法。
最初我setEditing并立即重新加载表数据。

I am edited the post to give context and some workarounds. Originally I setEditing and immediately reload the table data.

[tableView setEditing:YES animated:YES];
[tableView reloadData];

问题是表格在动画开始之前重新加载,因此动画从未见过。

The problem is that the table reloads before the animation begins, and so the animation is never seen.

以下是一些不同的解决方法:

Here are some various workarounds:

[tableView setEditing:YES animated:YES];
[self performSelector:@selector(ReloadTable) withObject:nil afterDelay:1.0];

这样可行,但如果延迟不正确,那么它看起来会很糟糕。所以我需要知道延迟是什么,我可以弄清楚,但我们并不认为延迟总是一样的。

This works but if I get the delay incorrect then it will look bad. So I need to know what the delay is, which I can figure out, but we are not gauranteed that the delay will always be the same.

isEditing = YES;
[tableView reloadData];
[tableView setEditing:YES animated:YES];

这可能有效,但表格的行为会有所不同,具体取决于我们是否处于编辑模式。所以我必须使用自己的isEditing变量而不是标准的UITableView.editing。我宁愿不必创建一个新的布尔isEditing变量。

This could work, but the table behaves differently depending on if we are in editing mode. So I have to use my own isEditing variable instead of the standard UITableView.editing. I would rather not have to create a new boolean isEditing variable.

[tableView setEditing:YES animated:YES];
[tableView insertRowsAtIndexPaths:path withRowAnimation:UITableViewRowAnimationTop];

这几乎运作良好但在编辑模式下第一行应该有UITableViewCellEditingStyleInsert,而其他行得到UITableViewCellEditingStyleDelete。使用上面的代码,在添加行之前设置编辑样式。因此第二行以UITableViewCellEditingStyleInsert结束。

This almost works well but in editing mode the first row should have the UITableViewCellEditingStyleInsert, while the other rows get UITableViewCellEditingStyleDelete. And with the above code the editing style gets set BEFORE the row is added. Therefore the second row ends up with UITableViewCellEditingStyleInsert.

推荐答案

[CATransaction begin];
[CATransaction setCompletionBlock: ^{
    // your animation has finished
}];
[tableView setEditing:YES animated:YES];
[CATransaction commit];

请注意 setCompletionBlock 必须在顶部。

这篇关于如何判断UITableView动画何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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