核心动画的接触点滴(二)
2016-05-30 12:25
295 查看
本篇记录核心动画中基础动画的使用:
一、简单介绍 CAPropertyAnimation的子类 属性解析: fromValue:keyPath相应属性的初始值 toValue:keyPath相应属性的结束值 随着动画的进行,在长度为duration的持续时间内,keyPath相应属性的值从fromValue渐渐地变为toValue 如果fillMode=kCAFillModeForwards和removedOnComletion=NO,那么在动画执行完毕后,图层会保持显示动画执行 后的状态。但在实质上,图层的属性值还是动画执行前的初始值,并没有真正被改变。 比如,CALayer的position初始值为(0,0),CABasicAnimation的fromValue为(10,10),toValue为(100,100),虽然动 画执行完毕后图层保持在(100,100)这个位置,实质上图层的position还是为(0,0)二、平移动画
在上面的代码中加上anima.delegate = self;即可
使用代理监听动画的执行过程(delegate)
三、缩放动画
只需要修改以下几点即可
[b]四、旋转动画[/b]
[b][b]需要修改以下几点即可[/b][/b]
anima.keyPath = @"transform"; //旋转
//1.2修改属性,执行动画(第一个参数为旋转的角度,后面三个分别是些x,y,z)
anima.byValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)];
一、简单介绍 CAPropertyAnimation的子类 属性解析: fromValue:keyPath相应属性的初始值 toValue:keyPath相应属性的结束值 随着动画的进行,在长度为duration的持续时间内,keyPath相应属性的值从fromValue渐渐地变为toValue 如果fillMode=kCAFillModeForwards和removedOnComletion=NO,那么在动画执行完毕后,图层会保持显示动画执行 后的状态。但在实质上,图层的属性值还是动画执行前的初始值,并没有真正被改变。 比如,CALayer的position初始值为(0,0),CABasicAnimation的fromValue为(10,10),toValue为(100,100),虽然动 画执行完毕后图层保持在(100,100)这个位置,实质上图层的position还是为(0,0)二、平移动画
//1.创建核心动画38 CABasicAnimation *anima=[CABasicAnimation animation]; //1.1告诉系统要执行什么样的动画 anima.keyPath=@"position"; //设置通过动画,将layer从哪儿移动到哪儿 anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)]; anima.toValue=[NSValue valueWithCGPoint:CGPointMake(200, 300)]; //1.2设置动画执行完毕之后不删除动画 anima.removedOnCompletion=NO; //1.3设置保存动画的最新状态50 anima.fillMode=kCAFillModeForwards; //2.添加核心动画到layer [self.myLayer addAnimation:anima forKey:nil];byValue和toValue的区别,前者是在当前的位置上增加多少,后者是到指定的位置。
在上面的代码中加上anima.delegate = self;即可
使用代理监听动画的执行过程(delegate)
//开始执行动画时调用 -(void)animationDidStart:(CAAnimation *)anim { NSLog(@"开始执行动画"); } //动画执行完毕后调用 -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { //动画执行完毕,打印执行完毕后的position值 NSString *str=NSStringFromCGPoint(self.myLayer.position); NSLog(@"执行后:%@",str); }
三、缩放动画
只需要修改以下几点即可
//1.1告诉系统要执行什么样的动画 anima.keyPath=@"bounds"; //设置通过动画,将layer从多大缩放到多大 anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)]; anima.toValue=[NSValue valueWithCGPoint:CGPointMake(200, 300)]; //同样也可以直接食用byValue直接从当前大小缩放到指定大小
[b]四、旋转动画[/b]
[b][b]需要修改以下几点即可[/b][/b]
anima.keyPath = @"transform"; //旋转
//1.2修改属性,执行动画(第一个参数为旋转的角度,后面三个分别是些x,y,z)
anima.byValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)];
相关文章推荐
- C#实现字体旋转的方法
- 基于jQuery实现的旋转彩圈实例
- C#数字图像处理之图像缩放的方法
- C++实现一维向量旋转算法
- C#使用Matrix执行缩放的方法
- C#实现缩放字体的方法
- 使用JavaScript实现旋转的彩圈特效
- jQuery平滑旋转幻灯片特效代码分享
- jquery实现图片按比例缩放示例
- jquery实现可旋转可拖拽的文字效果代码
- jQuery+CSS3实现3D立方体旋转效果
- C#中图片旋转和翻转(RotateFlipType)用法分析
- JS+css 图片自动缩放自适应大小
- jQuery实现响应浏览器缩放大小并改变背景颜色
- Android开发之图形图像与动画(二)Animation实现图像的渐变/缩放/位移/旋转
- JavaScript 拖拉缩放效果
- Java图片处理 (文字水印、图片水印、缩放、补白)代码实例
- Android Tween动画之RotateAnimation实现图片不停旋转效果实例介绍
- Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍
- jquery实现根据浏览器窗口大小自动缩放图片的方法