preface

UITableView is a common control used in iOS development. The ordinary display effect of tableView is rather stiff. In order to enhance the vitality of APP and improve the experience, we can operate Cell to achieve some animation effects according to the characteristics of tableView. I wrote a simple animation set TableViewAnimationKit, just need a line of code to make tableView implement animation there are currently about 10 animations, will be optimized to increase. Source code on Github: TableViewAnimationKit welcome everyone star, download, communication.

The body of the

1. Effect Display:

Two, use method

The methods that TableViewAnimationKit calls each animation are class methods that can be called in a single line of code. eg:

[TableViewAnimationKit shakeAnimationWithTableView:tableView];Copy the code

TableViewAnimationKit provides an animation class method

+ (void)moveAnimationWithTableView:(UITableView *)tableView;
+ (void)alphaAnimationWithTableView:(UITableView *)tableView;
+ (void)fallAnimationWithTableView:(UITableView *)tableView;
+ (void)shakeAnimationWithTableView:(UITableView *)tableView;
+ (void)overTurnAnimationWithTableView:(UITableView *)tableView;
+ (void)toTopAnimationWithTableView:(UITableView *)tableView;
+ (void)springListAnimationWithTableView:(UITableView *)tableView;
+ (void)shrinkToTopAnimationWithTableView:(UITableView *)tableView;
+ (void)layDonwAnimationWithTableView:(UITableView *)tableView;
+ (void)roteAnimationWithTableView:(UITableView *)tableView;Copy the code

Three, source code explanation

Let’s take one of the animations as an example:





+ (void)shakeAnimationWithTableView:(UITableView *)tableView {

    NSArray *cells = tableView.visibleCells;
    for (int i = 0; i < cells.count; i++) {
        UITableViewCell *cell = [cells objectAtIndex:i];
        if (i%2 == 0) {
            cell.transform = CGAffineTransformMakeTranslation(-XS_SCREEN_WIDTH,0);
        }else{ cell.transform = CGAffineTransformMakeTranslation(XS_SCREEN_WIDTH,0); } [UIView animateWithDuration: 0.4 delay: I * usingSpringWithDamping 0.03:0.75 initialSpringVelocity: 1/0.75 options: 0 animations:^{ cell.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { }]; }}Copy the code

The main idea is: obtain the visibleCells array of TableView, traverse, execute animation for each cell, the execution time and direction of different cells are different, together constitute the whole animation.

4. Some other animation effects





After the language

Source code on Github: TableViewAnimationKit have the need of students can download, star, currently only Demo level, after will continue to optimize, increase animation. If you have any ideas, welcome to technical exchange.