有没有办法指定 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/