IOS tableView 滑动动画

//tableview。五种 滑动 特效


//cell滑动动画
- (void)tableView:(UITableView *)tableView willDisplayCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
//    [APIConfig reloadAnimationATableView:tableView cell:cell indexPath:indexPath];
//    [APIConfig reloadAnimationBTableView:tableView cell:cell indexPath:indexPath];
//    [APIConfig reloadAnimationCTableView:tableView cell:cell indexPath:indexPath];
//    [APIConfig reloadAnimationDTableView:tableView cell:cell indexPath:indexPath];
    [APIConfig reloadAnimationETableView:tableView cell:cell indexPath:indexPath];
    
}

.h 文件


#import 
#import 


@interface APIConfig : NSObject


#pragma mark tableview 滑动动画
+ (void)reloadAnimationATableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath;
+ (void)reloadAnimationBTableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath;
+ (void)reloadAnimationCTableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath;
+ (void)reloadAnimationDTableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath;
+ (void)reloadAnimationETableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath;
@end

#import "APIConfig.h"
@implementation APIConfig

+ (void)reloadAnimationATableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath
{
    NSArray *array =  tableView.indexPathsForVisibleRows;
    NSIndexPath *firstIndexPath = array[0];
    //设置anchorPoint
    cell.layer.anchorPoint =CGPointMake(0,0.5);
    //为了防止cell视图移动,重新把cell放回原来的位置
    cell.layer.position =CGPointMake(0, cell.layer.position.y);
    //设置cell按照z轴旋转90度,注意是弧度
    if (firstIndexPath.row < indexPath.row) {
        cell.layer.transform =CATransform3DMakeRotation(M_PI_2,0,0,1.0);
    }else{
        cell.layer.transform =CATransform3DMakeRotation(-M_PI_2,0,0,1.0);
    }
    cell.alpha =0.0;
    [UIView animateWithDuration:1 animations:^{
        cell.layer.transform =CATransform3DIdentity;
        cell.alpha =1.0;
    }];
}
+ (void)reloadAnimationBTableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath{
    
    CATransform3D rotation;
    rotation = CATransform3DMakeRotation((90.0*M_PI/180), 0.0, 0.7, 0.4);
    rotation.m44 = 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.5, 0.5);
    [UIView beginAnimations:@"rotaion" context:NULL];
    [UIView setAnimationDuration:0.8];
    cell.layer.transform = CATransform3DIdentity;
    cell.alpha = 1;
    cell.layer.shadowOffset = CGSizeMake(0, 0);
    [UIView commitAnimations];
}

+ (void)reloadAnimationCTableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath{
    cell.contentView.alpha = 0.1;
    CGAffineTransform transformScale = CGAffineTransformMakeScale(2,2);
    CGAffineTransform transformTranslate = CGAffineTransformMakeTranslation(0, 0);
    cell.contentView.transform = CGAffineTransformConcat(transformScale, transformTranslate);
    [tableView bringSubviewToFront:cell.contentView];
    [UIView animateWithDuration:1 animations:^{
        cell.contentView.alpha = 1;
        cell.contentView.transform = CGAffineTransformIdentity;
    } completion:nil];
}


+ (void)reloadAnimationDTableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath{
    CGFloat rotationAngleDegrees = 0;
    CGFloat rotationAngleRadians = rotationAngleDegrees * (M_PI/180);
    CGPoint offsetPositioning = CGPointMake(-200, -20);
    CATransform3D transform = CATransform3DIdentity;
    transform = CATransform3DRotate(transform, rotationAngleRadians, 0.0, 0.0, 1.0);
    transform = CATransform3DTranslate(transform, offsetPositioning.x, offsetPositioning.y, 0.0);
    UIView *card = [cell contentView];
    card.layer.transform = transform;
    card.layer.opacity = 0.1;
    [UIView animateWithDuration:0.5f animations:^{
        card.layer.transform = CATransform3DIdentity;
        card.layer.opacity = 1;
    }];
}

+ (void)reloadAnimationETableView:(UITableView *_Nullable)tableView cell:(nonnull UITableViewCell *)cell indexPath:(nonnull NSIndexPath *)indexPath{
    cell.alpha = 0.5;
    CGAffineTransform transformScale = CGAffineTransformMakeScale(0.3,0.8);
    CGAffineTransform transformTranslate = CGAffineTransformMakeTranslation(0.5, 0.6);
    cell.transform = CGAffineTransformConcat(transformScale, transformTranslate);
    [tableView bringSubviewToFront:cell];
    [UIView animateWithDuration:1.0f
                          delay:0
                        options:UIViewAnimationOptionAllowUserInteraction
                     animations:^{
                         cell.alpha = 1;
                         //清空 transform
                         cell.transform = CGAffineTransformIdentity;
                     } completion:nil];
}
@end


你可能感兴趣的:(IOS tableView 滑动动画)