自定义动画--角度抖动、路径旋转、左右晃动
2016-07-12 15:43
260 查看
self.label1 = [[UILabelalloc]initWithFrame:CGRectMake(50,50,50,50)];
self.label1.backgroundColor = [UIColorredColor];
self.label1.text =@"旋转路径";
[self.viewaddSubview:self.label1];
//图标抖动动画
CAKeyframeAnimation * keyAnimaion = [CAKeyframeAnimationanimation];
keyAnimaion.keyPath =@"transform.rotation";
keyAnimaion.values =@[@(-10 /180.0 *
M_PI),@(10 /180.0 *M_PI),@(-10/180.0
* M_PI),@(0)];//度数转弧度
keyAnimaion.removedOnCompletion =NO;
keyAnimaion.fillMode =kCAFillModeForwards;
keyAnimaion.duration =0.2;
keyAnimaion.repeatCount =MAXFLOAT;
[self.label1.layeraddAnimation:keyAnimaion
forKey:nil];
//******************************//
//路径加旋转动画组合
//添加路径
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 0, 0);
CGPathAddCurveToPoint(path, nil, 0, 0, 200, 100, 0, 400);
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards ;
animation.timingFunction = [CAMediaTimingFunction functionWithName : kCAMediaTimingFunctionEaseIn];
animation.autoreverses = NO ;
animation.duration = 1;
animation.repeatCount = MAXFLOAT;
//添加旋转
CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 50 , 100 , 0);
CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform"];
animation1.toValue = [ NSValue valueWithCATransform3D :rotationTransform];
animation1.duration = 0.1;
animation1.autoreverses = YES ;
animation1.cumulative = NO ;
animation1.fillMode = kCAFillModeForwards ;
animation1.repeatCount = MAX_INPUT;
[self.label1.layer addAnimation:animation forKey:@"旋转路径"];
[self.label1.layer addAnimation:animation1 forKey:nil];
/***********************************/
//左右晃动动画
CAKeyframeAnimation * animation = [CAKeyframeAnimation
animationWithKeyPath:@"transform.translation.x"];
CGFloat currentTx =
self.label1.transform.ty;
NSLog(@"%f",currentTx);
// animation.delegate = self;
animation.duration =
0.5;
animation.values =
@[ @(currentTx),
@(currentTx + 10),
@(currentTx-8),
@(currentTx + 8),
@(currentTx -5),
@(currentTx + 5),
@(currentTx)
];
animation.repeatCount =
5;
//时间段
//animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];
//动画出现先快后慢
//animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.label1.layer
addAnimation:animation forKey:nil];
相关文章推荐
- 浏览器缓存知识小结及应用
- 2使用struts2的标签库 EL表达式
- numpy module 2 -- Numpy Tutorial2
- 使用反射实现动态权限
- Maven +EasyMock+Junit 小例子
- oracle基础三 与长字符串根据操作符分割成数组处理函数
- 1使用Struts2
- Extjs 点击复选框在表格中增加相关信息行
- NDK 编译报错:request for member 'FindClass' in something not a structure or union
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation
- 动态规划(三)最长递增子序列
- 安装包评审验证测试
- window JNI_CreateJavaVM启动java程序
- 依赖库Underscore系列(3)-函数
- 字符串逆序输出
- Maven更新父子模块的版本号
- Hex编码字节
- 【NOIP2013模拟11.5A组】游戏节目
- iptables规则的查看、添加、删除和修改
- 【android学习】socket传输中,流的关闭