【问题标题】:insertRowsAtIndexPaths with 2 animations带有 2 个动画的 insertRowsAtIndexPaths
【发布时间】:2014-08-14 10:11:46
【问题描述】:

我目前正在使用以下代码在我的UITableView 中插入单元格:

[rottenTableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationTop];

它使用动画UITableViewRowAnimationTop 正确完成了这项工作。但是,我想同时插入带有 2 个动画的单元格(UITableViewRowAnimationTopUITableViewRowAnimationFade)。我尝试了以下方法:

[rottenTableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:(UITableViewRowAnimationTop|UITableViewRowAnimationFade)];

这段代码似乎与之前的插入动画没有任何不同。有什么方法可以同时执行这两个动画?

【问题讨论】:

  • 您是否尝试将插入调用拆分为顶部动画的插入调用和淡入淡出动画的插入调用?
  • (UITableViewRowAnimationTop|UITableViewRowAnimationFade) 不起作用的原因是UITableViewRowAnimation 是一个枚举,而不是位掩码。使用[tableView beginUpdates][tableView endUpdates],将行插入不同动画的不同行。
  • @Jeff,在两个不同的行中插入相同的行会插入两次,不是吗?
  • 对不起,我误读了您的问题,我以为您想插入两个具有不同动画的不同单元格。不可能同时使用两个预定义动画,它是一个枚举,意味着它们不能被或在一起。

标签: ios uitableview


【解决方案1】:

据我所知,当您使用-insertRowsAtIndexPaths:withRowAnimation: 时,单个单元格可能同时只有一种动画类型。但我可以建议同时为不同的单元格使用不同的动画类型。为此,您可以使用beginUpdates/endUpdates 来批量更新 UITableView 单元格。所有的动画会同时触发,你可以这样使用:

[tableView beginUpdates];

[tableView insertRowsAtIndexPaths:insertIndexPaths1 withRowAnimation:UITableViewRowAnimationRight];
[tableView insertRowsAtIndexPaths:insertIndexPaths2 withRowAnimation:UITableViewRowAnimationOTHER];

[tableView endUpdates];

详情请查看:Batch Insertion, Deletion, and Reloading of Rows and Sections.
还要检查这个关于自定义插入动画的问题:Can you do custom animations for UITableView Cell Inserts?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 2012-09-27
    • 2012-06-22
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    相关资源
    最近更新 更多