zoukankan      html  css  js  c++  java
  • CATransform3D的使用以及各个参数的含义

    1. 缩放

    CABasicAnimation *theAnimation=[CABasicAnimation animationWithKeyPath:@"transform"];
        //x,y,z放大缩小倍数
        CATransform3D transform=CATransform3DMakeScale(0.5, 0.5, 1.0);
        NSValue *value=[NSValue valueWithCATransform3D:transform];
        [theAnimation setToValue:value];
        
        
        transform=CATransform3DMakeScale(1.0, 1.0, 1.0);
        value=[NSValue valueWithCATransform3D:transform];
        
        [theAnimation setAutoreverses:YES];  //原路返回的动画一遍
        [theAnimation setDuration:1.0];//执行动画的时间
        [theAnimation setRepeatCount:2];//执行动画的次数
        
        [layer addAnimation:theAnimation forKey:nil];

    2.动画旋转

    CABasicAnimation *theAnimation=[CABasicAnimation animationWithKeyPath:@"transform"];
        CATransform3D transform=CATransform3DMakeRotation(90*M_PI/180, 1, 1, 0);//
        NSValue *value = [NSValue valueWithCATransform3D:transform];
        [theAnimation setToValue:value];

       /*
         angle:旋转的弧度,所以要把角度转换成弧度:角度 * M_PI / 180。
         
         x:向X轴方向旋转。值范围-1 --- 1之间
         
         y:向Y轴方向旋转。值范围-1 --- 1之间
         
         z:向Z轴方向旋转。值范围-1 --- 1之间
         向 X轴,Y轴都旋转60度,就是沿着对角线旋转。
         */
        transform = CATransform3DMakeRotation(1, 1, 1, 0);
        value = [NSValue valueWithCATransform3D:transform];
        [theAnimation setFromValue:value];
        theAnimation.duration=2;
        theAnimation.autoreverses=YES;
        [layer addAnimation:theAnimation forKey:nil];

    3.组动画

    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];

        CATransform3D rotateTransform = CATransform3DMakeRotation(1.57, 0, 0, -1);
        CATransform3D scaleTransform = CATransform3DMakeScale(2, 2, 2);
        //(CGFloat tx,CGFloat ty, CGFloat tz ,x,y,z轴的偏移量
        CATransform3D positionTransform = CATransform3DMakeTranslation(1, 200, 0); //位置移动
        CATransform3D combinedTransform =CATransform3DConcat(rotateTransform, scaleTransform); //Concat就是combine的意思
        combinedTransform = CATransform3DConcat(combinedTransform, positionTransform); //再combine一次把三个动作连起来
        
        [anim setFromValue:[NSValue valueWithCATransform3D:CATransform3DIdentity]]; //放在3D坐标系中最正的位置
        [anim setToValue:[NSValue valueWithCATransform3D:combinedTransform]];
        [anim setDuration:5.0f];
        
        [layer addAnimation:anim forKey:nil];
        
        [layer setTransform:combinedTransform];  //如果没有这句,layer执行完动画又会返回最初的state

     
  • 相关阅读:
    [转载]自定义Behavior 实现Listbox自动滚动到选中项
    [转载]使用Express3.0实现<Node.js开发指南>中的微博系统
    【转载】Node.js + Express 多个 Layout 文件应用
    [转载]node.js之 express框架+ejs模板 windows下建站点
    微软中国软件下载中心
    {转载}【真正的Expression Blend实战开发技巧】
    [转载]WPF窗口跳转及window和page区别
    paip.java c++得到当前类,方法名称以及行号
    paip.简化字手写参考二简字..共98个
    paip.文件读写api php java python总结.txt
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/5001676.html
Copyright © 2011-2022 走看看