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

后端 未结 3 1632
闹比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: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];
    

提交回复
热议问题