ios - UITableView 行动画持续时间和完成回调

标签 ios iphone uitableview animation cocoa-touch

有没有办法指定 UITableView 行动画的持续时间,或者在动画完成时获得回调?

我想做的是在动画完成后闪烁滚动指示器。在那之前做闪光灯不会做任何事情。到目前为止,我的解决方法是延迟半秒(这似乎是默认的动画持续时间),即:

[self.tableView insertRowsAtIndexPaths:newRows
                      withRowAnimation:UITableViewRowAnimationFade];
[self.tableView performSelector:@selector(flashScrollIndicators)
                     withObject:nil
                     afterDelay:0.5];

最佳答案

刚刚遇到这个。方法如下:

objective-C

[CATransaction begin];
[tableView beginUpdates];
[CATransaction setCompletionBlock: ^{
    // Code to be executed upon completion
}];
[tableView insertRowsAtIndexPaths: indexPaths
                 withRowAnimation: UITableViewRowAnimationAutomatic];
[tableView endUpdates];
[CATransaction commit];

swift

CATransaction.begin()
tableView.beginUpdates()
CATransaction.setCompletionBlock {
    // Code to be executed upon completion
}
tableView.insertRowsAtIndexPaths(indexArray, withRowAnimation: .Top)
tableView.endUpdates()
CATransaction.commit()

关于ios - UITableView 行动画持续时间和完成回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3832474/

相关文章:

ios - 使用 NSPredicate 的变量格式化异常

ios - GLKit 内存泄漏 copywithZone

iphone - 在 iOS 应用程序中对 Sqlite 的写访问

objective-c - 如何用 ASIHttpRequest JSON 数据填充 UITableView?

ios - 没有 Storyboard的自定义 UITableViewCell 不显示

ios - 删除 UIView 中 TableView 的记录

ios - 使用 corebluetooth 将大型二进制字符串从 ios 应用程序传输到 BLE 设备

xcode - iOS4.1 SDK 中单个库的重复符号

ios - TableView Cell 自定义类型 Text 自身重叠或为空白

iphone - 简单的 UITapGestureRecognizer。 IBAction 未触发