完成类似百度贴吧客户端tableview滑动效果

本文介绍如何在UITableView中使用CATransform3D实现单元格的缩放和淡入动画效果,并提供了一个具体的实现示例代码。

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

效果请点击下方youku链接:
http://v.youku.com/v_show/id_XOTE4NzMyNjA0.html

在UITableViewDelegate的

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

方法中实现如下代码:

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

    [self tableView:tableView cellWillDisplay:cell forRowAtIndex:indexPath.row];

}


-(void)tableView:(UITableView *)tableView cellWillDisplay:(UITableViewCell *)cell forRowAtIndex:(NSInteger )rowOrSection{

        //设置初始状态
    CATransform3D translation;

    translation = CATransform3DMakeScale(1.2, 1.2, 1.2);   //x,y,z放大1.2倍

    cell.alpha = 0;   //先设置为全透明

    cell.layer.transform = translation;

    cell.layer.anchorPoint = CGPointMake(0, 0.5); //改变锚点

    if (cell.layer.position.x != 0) {

        cell.layer.position = CGPointMake(0, cell.layer.position.y);   //确认中心点

    }

    //添加动画

    [UIView beginAnimations:@"translation"    //动画方式
                    context:NULL];

    [UIView setAnimationDuration:0.4]; //动画时间

    cell.layer.transform = CATransform3DIdentity;  //x,y,z变为原来的大小

    cell.alpha = 1;    //渐变为不透明

    cell.layer.shadowOffset = CGSizeMake(0, 0); //偏移量归0

    [UIView commitAnimations];

}

Demo下载地址:
http://download.youkuaiyun.com/detail/u013531246/8518699

另外,如果只需要对未加载的数据进行动画显示的话,个人建议是在tableview数据源中的每一个数据添加一个Bool类型的标志位,根据这个标志位来判断是否已经被加载过,如果没有加载过就执行动画。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值