UITableViewCell的一些动画

UITableViewCell的一些动画

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    //[self leftInsertAnimation:cell];
    //[self springAnimation_1:cell];
    //[self springAnimation_2:cell];
    //[self left3DAnimation:cell];
    [self flyInAnimation:cell];
}

1、左侧插入动画

-(void) leftInsertAnimation:(UITableViewCell*)cell{
    CGPoint center = cell.center;
    CGPoint orgCenter = center;
    center.x += cell.bounds.size.width;
    cell.center = center;

    [UIView animateWithDuration:0.5 animations:^{
        cell.center = orgCenter;
    }];
}

2、弹簧效果

-(void) springAnimation_1:(UITableViewCell*)cell{
    CGPoint center = cell.center;
    CGPoint orgCenter = center;
    center.y += cell.bounds.size.height;
    cell.center = center;
    
    [UIView animateWithDuration:0.5 animations:^{
        cell.center = orgCenter;
    }];
}

3、折叠展开效果

-(void) springAnimation_2:(UITableViewCell*)cell{
    
    cell.transform = CGAffineTransformMakeTranslation(0, -80);
    
    [UIView animateWithDuration:0.5 animations:^{
        cell.transform = CGAffineTransformIdentity;
    }];
}

4、左侧3D变幻效果

-(void) left3DAnimation:(UITableViewCell*) cell{
    CATransform3D rotation;
    rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
    rotation.m34 = 1.0/ -600;
    
    cell.layer.shadowColor = [[UIColor blackColor]CGColor];
    cell.layer.shadowOffset = CGSizeMake(10, 10);
    cell.alpha = 0;
    cell.layer.transform = rotation;
    cell.layer.anchorPoint = CGPointMake(0, 0.5);
    
    [UIView beginAnimations:@"rotation" context:NULL];
    [UIView setAnimationDuration:0.8];
    
    cell.layer.transform = CATransform3DIdentity;
    cell.alpha = 1;
    cell.layer.shadowOffset = CGSizeMake(0, 0);
        
    [UIView commitAnimations];
}

5、底部飞入效果

-(void) flyInAnimation:(UITableViewCell*) cell{

    cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
    //x和y的最终值为1
    [UIView animateWithDuration:1 animations:^{
        cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
    }];
}

6、绕Z轴旋转

cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1.0);
    [UIView animateWithDuration:0.4 animations:^{
        cell.layer.transform = CATransform3DMakeScale(1.0, 1.0, 1.0);
    }];

另:也可根据indexPath来控制旧数据和新数据是否动画,自己可根据需求自定义动画效果

你可能感兴趣的:(UITableViewCell的一些动画)