几种cell动画

这篇博客介绍了如何在UITableView中为单元格(cell)添加动画效果。在`willDisplayCell`方法中,通过设置cell的layer属性,包括阴影颜色、偏移、透明度和缩放变换,实现了两种不同的动画效果:一种是渐显并平滑调整阴影和尺寸;另一种是通过改变高度和位置,配合alpha值变化,实现淡入和高度变化的动画。这些动画为表格视图增添了视觉吸引力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 1 && indexPath.section <2) {

        cell.layer.shadowColor = [[UIColor blackColor] CGColor];

        cell.layer.shadowOffset = CGSizeMake(10, 10);

        cell.alpha = 0;

        cell.layer.transform = CATransform3DMakeScale(0.5, -0.15, 1);

        cell.layer.anchorPoint = CGPointMake(0.5, -0.5);

        

        // define final state (e.g. after animation) & commit animation

        [UIView beginAnimations:@"scaleTableViewCellAnimationID" context:NULL];

        [UIView setAnimationDuration:1];

        cell.layer.shadowOffset = CGSizeMake(0, 0);

        cell.alpha = 1;

        cell.layer.transform = CATransform3DIdentity;

        [UIView commitAnimations];

    }

    

}




-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    if ([[NSUserDefaults standardUserDefaults]boolForKey:kCouponCacheFlag] ) {

        if (indexPath.row == 1 && indexPath.section <2) {

//            cell.layer.shadowColor = [[UIColor blackColor] CGColor];

//            cell.layer.shadowOffset = CGSizeMake(10, 10);

//            cell.alpha = 0;

//            cell.layer.transform = CATransform3DMakeScale(1, -1, 1);

//            cell.layer.anchorPoint = CGPointMake(0.5, -0.5);

            cell.height = 64 ;

            cell.alpha = 0;

            cell.top = cell.top-96;

            [UIView animateWithDuration:.8 delay:indexPath.section*.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{

                cell.layer.shadowOffset = CGSizeMake(0, 0);

                cell.alpha = 1;

//                cell.layer.transform = CATransform3DIdentity;

                cell.height = 96;

                cell.top = 0;


            } completion:^(BOOL finished) {

                

            }];


        }

  

    }

    

}



//This function is where all the magic happens

//-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

//    if (indexPath.row ==1) {

//        if(kAnimationFlag==2)

//            return;

//        CGFloat originHeight = cell.height;

//        cell.top = -originHeight;

//        cell.height = 0;

//      [UIView animateWithDuration:.2*(indexPath.section+2)

//                       delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

//                           cell.top = 0;

//                           cell.height = originHeight;

//                           kAnimationFlag ++;

//                       } completion:^(BOOL finished){

//                           kAnimationFlag--;

//                       }];

//    }


////    //1. Setup the CATransform3D structure

////    CATransform3D rotation;

////    rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);

////    rotation.m34 = 1.0/ -600;

////

////    //2. Define the initial state (Before the animation)

////  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);

//

////3. Define the final state (After the animation) and commit the animation

//[UIView beginAnimations:@"postio" context:NULL];

//[UIView setAnimationDuration:0.8];

//cell.layer.transform = CATransform3DIdentity;

//cell.alpha = 1;

//cell.layer.shadowOffset = CGSizeMake(0, 0);

//[UIView commitAnimations];

//    }

//}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值