美文网首页IOS技术型
tableViewCell对象添加3D旋转动画

tableViewCell对象添加3D旋转动画

作者: 衹氏 | 来源:发表于2016-05-09 01:12 被阅读335次

    3D仿射变换动画类型同二维2D仿射变换动画一样有旋转平移缩放


    CATransform3DMakeScale(0.5, 0.5, 1.0);  //x,y,z放大缩小倍数

    CATransform3DMakeRotation(1.57, 1, 1, 0); //1.57表示所转角的弧度 = 90Pi/180 = 90*3.14/180

    CATransform3DMakeTranslation(0, 0, 0); //位置移动


    目的:在tableViewCell对象即将出现时添加动画效果,tableview代理方法如下:


    //添加每个cell出现时的3D动画

    (方法一)

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

    //*************************************获取变换对象*******************

    //Transform3D对应4阶矩阵

    CATransform3D rotation;//定义3D旋转对象

    rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);//3D旋转对象初始化//角度控制

    //逆时针旋转

    rotation.m34 = 1.0/ -600;//4阶矩阵的第3行第4列更改

    //*************************************获取变换对象*******************

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

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

    cell.alpha = 0;

    cell.layer.transform = rotation;//*****关键点****

    //启动旋转动画

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

    //旋转时间

    [UIView setAnimationDuration:0.8];

    //恢复原状

    cell.layer.transform = CATransform3DIdentity;

    cell.alpha = 1;

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

    [UIView commitAnimations];

    }


    (方法二)

    //添加每个cell出现时的3D动画

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

    CATransform3D rotation;//定义3D旋转对象

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

    rotation.m34 = 1.0/ -600;

    cell.contentView.layer.transform = rotation;

    cell.contentView.layer.anchorPoint=CGPointMake(0, 3);//旋转锚点

    [UIView animateWithDuration:0.8 animations:^{//先启动前一个动画,待结束后再启动动画模块中的动画指令

    cell.contentView.layer.transform =CATransform3DIdentity;

    cell.alpha=1;

    }];

    }



    相关文章

      网友评论

        本文标题:tableViewCell对象添加3D旋转动画

        本文链接:https://www.haomeiwen.com/subject/kmterttx.html