Change duration of UITableView animation (Insert/Delete rows with table beginUpdates)

后端 未结 3 1625
闹比i
闹比i 2020-12-16 13:02

Is there a way to change the duration of [table beginUpdates]/[table endUpdates] animations?

This is what I\'ve tried, with no luck:

相关标签:
3条回答
  • 2020-12-16 13:29

    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
    }];
    
    0 讨论(0)
  • 2020-12-16 13:32

    @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];
    
    0 讨论(0)
  • 2020-12-16 13:55

    Here is the Swift version of Gautam Jain's answer

    0 讨论(0)
提交回复
热议问题