您的位置:首页 > 其它

给TableView或者CollectionView的cell添加简单动画

2016-06-30 10:43 405 查看
只要在willDisplayCell方法中对将要显示的cell做动画即可:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(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)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{

        

        

        if (indexPath.row %
2 != 0) {

            cell.transform = CGAffineTransformTranslate(cell.transform, kScreenWidth/2,
0);

        }else{

            cell.transform = CGAffineTransformTranslate(cell.transform, -kScreenWidth/2,
0);

        }

        cell.alpha = 0.0;

        [UIView animateWithDuration:0.7 animations:^{

            cell.transform = CGAffineTransformIdentity;

            cell.alpha = 1.0;

        } completion:^(BOOL finished) {

            

            

        }];

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: