CATransform3D的使用以及各个参数的含义
2015-11-27 20:38
447 查看
[b]1. 缩放[/b]
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
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
相关文章推荐
- LYSE-高阶函数
- 自己的第一个单片机程序
- Ubuntu 安装 cscope 和 ctags
- Cmd命令行编译c#文件
- 搞不定linux下的无线网卡驱动的权宜之计
- net-snmp源码VS2013编译添加加密支持(OpenSSL)
- 第13周—项目4 Floyd算法验证
- 冒泡排序函数,可以给任意类型的数据排序,比如整形数组,字符数组,字符串数组等
- iOS开发49-iOS Mac OS X Openfire的安装与卸载
- NavigationController
- javascript的navigator对象
- 异步流程控制库GoWithTheFlow
- 源码解析EventBus
- 1008. Elevator (20)
- [BZOJ1787][Ahoi2008]Meet 紧急集合&&[BZOJ1832][AHOI2008]聚会
- iOS修改tabbar的背景颜色
- 1008. Elevator (20)
- 获得每日,每周,每月的0点和24点的时间戳
- 小刚之问引发的思索
- hdoj Coprime 5072 (容斥原理) 好题***