Изменение продолжительности анимации 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];
Ответы
Ответ 1
Почему бы вам не попробовать анимацию UIView.
[UIView animateWithDuration:2 delay:0.2 options:UIViewAnimationOptionCurveEaseInEaseOut animations:^{
[self.tableView beginUpdates];
[self.tableView endUpdates];
} completion:^(BOOL finished) {
// code
}];
Ответ 2
Решение @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];