Is there a way to either specify the duration for UITableView row animations, or to get a callback when the animation completes?
What I would like to do is flash the scroll indicators after the animation completes. Doing the flash before then doesn't do anything. So far the workaround I have is to delay half a second (that seems to be the default animation duration), i.e.:
[self.tableView insertRowsAtIndexPaths:newRows withRowAnimation:UITableViewRowAnimationFade]; [self.tableView performSelector:@selector(flashScrollIndicators) withObject:nil afterDelay:0.5];
Just came across this. Here's how to do it:
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()
Expanding on karwag's fine answer, note that on iOS 7, surrounding the CATransaction with a UIView Animation offers control of the table animation duration.
[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];
The UIView animation's duration has no effect on iOS 6. Perhaps iOS 7 table animations are implemented differently, at the UIView level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With