Uitableview Row Animation Duration and Completion Callback

UITableView row animation duration and completion callback

Nowadays if you want to do this there is new function starting from iOS 11:

- (void)performBatchUpdates:(void (^)(void))updates 
completion:(void (^)(BOOL finished))completion;

In updates closures you place the same code as in beginUpdates()/endUpdates section. And the completion is executed after all animations.

How do I wait until a UITableView built-in animation is complete?

Thank you Iducool for pointing me to the other question.

This worked...

[CATransaction begin];
[CATransaction setCompletionBlock:^{
[self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
}];

[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];

[CATransaction commit];

I didn't seem to require UITableView's beginUpdates and endUpdates.

UITableView, how to catch the end of animation?

The animation is controlled by a instance of class CAAnimation. This class supports a method - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag which will be delivered to the delegate of this instance. This information is typically used to get informed on the completion.

In regard to your special request i would have a look at the UIView Class reference. There are several tasks that deal with animations of that view - which is the base class of UITableView. Therefore anything that is valid for UIView should have effect on the table view.

How to detect when animation completes on UITableViewCell deselect row

[CATransaction begin];

[tableView beginUpdates];

[CATransaction setCompletionBlock: ^{

NSLog(@"Completion code here");

}];

[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView endUpdates];

[CATransaction commit];


Related Topics



Leave a reply



Submit