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

是否可以指定UITableView行动画的持续时间,或者在动画完成时获取回调?


我想做的是在动画完成后闪烁滚动指示器。在此之前进行闪光灯不会执行任何操作。到目前为止,我要解决的问题是延迟半秒(这似乎是默认的动画持续时间),即:


[self.tableView insertRowsAtIndexPaths:newRows

                      withRowAnimation:UITableViewRowAnimationFade];

[self.tableView performSelector:@selector(flashScrollIndicators)

                     withObject:nil

                     afterDelay:0.5];


慕田峪9158850
浏览 913回答 3
3回答

Cats萌萌

请注意,在iOS 7上,使用UIView Animation将CATransaction围绕起来可以控制表格动画的持续时间。[UIView beginAnimations:@"myAnimationId" context:nil];[UIView setAnimationDuration:10.0]; // Set duration here[CATransaction begin];[CATransaction setCompletionBlock:^{    NSLog(@"Complete!");}];[myTable beginUpdates];// my table changes[myTable endUpdates];[CATransaction commit];[UIView commitAnimations];UIView动画的持续时间对iOS 6无效。也许在UIView级别,iOS 7表格动画的实现方式有所不同。

动漫人物

如今,如果要执行此操作,则可以从iOS 11开始使用新功能:- (void)performBatchUpdates:(void (^)(void))updates                  completion:(void (^)(BOOL finished))completion;在更新闭包中,放置与beginUpdates()/ endUpdates部分相同的代码。并且在所有动画之后执行完成。

墨色风雨

刚遇到这个。方法如下:目标C[CATransaction begin];[tableView beginUpdates];[CATransaction setCompletionBlock: ^{    // Code to be executed upon completion}];[tableView insertRowsAtIndexPaths: indexPaths                 withRowAnimation: UITableViewRowAnimationAutomatic];[tableView endUpdates];[CATransaction commit];迅速CATransaction.begin()tableView.beginUpdates()CATransaction.setCompletionBlock {    // Code to be executed upon completion}tableView.insertRowsAtIndexPaths(indexArray, withRowAnimation: .Top)tableView.endUpdates()CATransaction.commit()
打开App,查看更多内容
随时随地看视频慕课网APP