UITableView动画完成回调


UITableView 刷新代码块动画执行完成的回调

[CATransaction begin];

[tableView beginUpdates];

//...

[CATransaction setCompletionBlock: ^{
    // Code to be executed upon completion
}];

[tableView insertRowsAtIndexPaths: indexPaths
                 withRowAnimation: UITableViewRowAnimationAutomatic];


[tableView endUpdates];


[CATransaction commit];

让reloadData 执行时产生渐变动画

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.rowCount = 2;
    self.height = 20;
    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addTable)], [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadTable)]];

    [self reload:^{

    }];
}

- (void)addTable {
    self.rowCount += 2;
    self.height = 38;

    [self reload:^{

    }];
}

- (void)reloadTable {

    self.rowCount -=1;
    self.height = 50;

    [self reload:^{

    }];
}

- (void)reload:(void (^)(void))completion {
     ///  让reloadData产生渐变动画
    [UIView transitionWithView:self.tableView duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        [self.tableView reloadData];
    } completion:^(BOOL finished) {
        if (completion) {
            completion();
        }
    }];
}

.....
@end

附件: