Is there a way to change the duration of [table beginUpdates]
/[table endUpdates]
animations?
This is what I've tried, with no luck:
Option 1:
[UIView animateWithDuration:5.0 delay:0.0 options:(UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionOverrideInheritedDuration) animations:^{
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:indexPaths] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
} completion:^(BOOL finished) {
}];
Option 2:
[CATransaction begin];
[CATransaction setCompletionBlock:^{
NSLog(@"I actually get called!");
}];
[CATransaction setAnimationDuration:5.0]; //but I don't work
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:indexPaths] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
[CATransaction commit];
Why don't you try UIView animation.
[UIView animateWithDuration:2 delay:0.2 options:UIViewAnimationOptionCurveEaseInEaseOut animations:^{
[self.tableView beginUpdates];
[self.tableView endUpdates];
} completion:^(BOOL finished) {
// code
}];
Here is the Swift version of Gautam Jain's answer 😉:
UIView.animate(withDuration: 2.0, delay: 0.0, options: .curveEaseInOut, animations: {
self.tableView.beginUpdates()
// ...
self.tableView.endUpdates()
}) { isFinished in
// ...
}
@Gautam Jain 's solution is great. However, it has a problem, at least in iOS 9: the completion block will be executed at once but not when the animation completes.
I usually do like below, with a little more code but works better.
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:0.25];
[CATransaction begin];
[CATransaction setCompletionBlock:^{
// completion block
}];
[self.tableView beginUpdates];
// updates
[self.tableView endUpdates];
[CATransaction commit];
[UIView commitAnimations];
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