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

来源:互联网 发布:税控盘软件官网 编辑:程序博客网 时间:2024/06/04 18:47

效果请点击下方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.csdn.net/detail/u013531246/8518699

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

0 0