更改UITableView动画的持续时间(使用表beginUpdates插入/删除行)
有没有办法改变[table beginUpdates]
/ [table endUpdates]
动画的持续时间?
这是我尝试过的,没有运气:
选项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) { }];
选项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];
你为什么不尝试UIView动画。
[UIView animateWithDuration:2 delay:0.2 options:UIViewAnimationOptionCurveEaseInEaseOut animations:^{ [self.tableView beginUpdates]; [self.tableView endUpdates]; } completion:^(BOOL finished) { // code }];
@Gautam Jain的解决方案很棒。 但是,它有一个问题,至少在iOS 9中:完成块将立即执行,但不会在动画完成时执行。
我通常喜欢下面的代码,但代码更多,但效果更好。
[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];