CABasicAnimation animationWithKeyPath Types
转自:http://www.cnblogs.com/pengyingh/articles/2379631.html
CABasicAnimation animationWithKeyPath 一些规定的值
CABasicAnimation animationWithKeyPath Types
When using the ‘CABasicAnimation’ from the QuartzCore Framework in Objective-C, you have to specify an animationWithKeyPath. This is a long string and is not easily listed in the CABasicAnimation, CAPropertyAnimation, or the CAAnimation class. I ended up finding a handy chart within the Core Animation Programming guide in Apple’s iPhone OS Reference Library. Hope this helps save someone time, at least it will for me.
- CABasicAnimation *theAnimation;
- theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
- theAnimation.delegate = self;
- theAnimation.duration = 1;
- theAnimation.repeatCount = 0;
- theAnimation.removedOnCompletion = FALSE;
- theAnimation.fillMode = kCAFillModeForwards;
- theAnimation.autoreverses = NO;
- theAnimation.fromValue = [NSNumber numberWithFloat:0];
- theAnimation.toValue = [NSNumber numberWithFloat:-60];
- [self.view.layer addAnimation:theAnimation forKey:@"animateLayer"];
- 我们可以通过animationWithKeyPath键值对的方式来改变动画
- animationWithKeyPath的值:
- transform.scale = 比例轉換
- transform.scale.x = 闊的比例轉換
- transform.scale.y = 高的比例轉換
- transform.rotation.z = 平面圖的旋轉
- opacity = 透明度
- margin
- zPosition
- backgroundColor
- cornerRadius
- borderWidth
- bounds
- contents
- contentsRect
- cornerRadius
- frame
- hidden
- mask
- masksToBounds
- opacity
- position
- shadowColor
- shadowOffset
- shadowOpacity
- shadowRadius
- [self. ui_View.layer removeAllAnimations];
- CABasicAnimation *pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
- pulse.duration = 0.5 + (rand() % 10) * 0.05;
- pulse.repeatCount = 1;
- pulse.autoreverses = YES;
- pulse.fromValue = [NSNumber numberWithFloat:.8];
- pulse.toValue = [NSNumber numberWithFloat:1.2];
- [self.ui_View.layer addAnimation:pulse forKey:nil];
- // bounds
- CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"bounds"];
- anim.duration = 1.f;
- anim.fromValue = [NSValue valueWithCGRect:CGRectMake(0,0,10,10)];
- anim.toValue = [NSValue valueWithCGRect:CGRectMake(10,10,200,200)];
- anim.byValue = [NSValue valueWithCGRect:self. ui_View.bounds];
- // anim.toValue = (id)[UIColor redColor].CGColor;
- // anim.fromValue = (id)[UIColor blackColor].CGColor;
- anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- anim.repeatCount = 1;
- anim.autoreverses = YES;
- [ui_View.layer addAnimation:anim forKey:nil];
- //cornerRadius
- CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
- anim2.duration = 1.f;
- anim2.fromValue = [NSNumber numberWithFloat:0.f];
- anim2.toValue = [NSNumber numberWithFloat:20.f];
- anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- anim2.repeatCount = CGFLOAT_MAX;
- anim2.autoreverses = YES;
- [ui_View.layer addAnimation:anim2 forKey:@"cornerRadius"];
- //contents
- CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"contents"];
- anim.duration = 1.f;
- anim.fromValue = (id)[UIImage imageNamed:@"1.jpg"].CGImage;
- anim.toValue = (id)[UIImage imageNamed:@"2.png"].CGImage;
- // anim.byValue = (id)[UIImage imageNamed:@"3.png"].CGImage;
- // anim.toValue = (id)[UIColor redColor].CGColor;
- // anim.fromValue = (id)[UIColor blackColor].CGColor;
- anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- anim.repeatCount = CGFLOAT_MAX;
- anim.autoreverses = YES;
- [ui_View.layer addAnimation:anim forKey:nil];
- [ui_View.layer setShadowOffset:CGSizeMake(2,2)];
- [ui_View.layer setShadowOpacity:1];
- [ui_View.layer setShadowColor:[UIColor grayColor].CGColor];
- //
- CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowColor"];
- anim.duration = 1.f;
- anim.toValue = (id)[UIColor redColor].CGColor;
- anim.fromValue = (id)[UIColor blackColor].CGColor;
- anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- anim.repeatCount = CGFLOAT_MAX;
- anim.autoreverses = YES;
- [ui_View.layer addAnimation:anim forKey:nil];
- CABasicAnimation *_anim = [CABasicAnimation animationWithKeyPath:@"shadowOffset"];
- _anim.duration = 1.f;
- _anim.fromValue = [NSValue valueWithCGSize:CGSizeMake(0,0)];
- _anim.toValue = [NSValue valueWithCGSize:CGSizeMake(3,3)];
- _anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- _anim.repeatCount = CGFLOAT_MAX;
- _anim.autoreverses = YES;
- [ui_View.layer addAnimation:_anim forKey:nil];
- CABasicAnimation *_anim1 = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
- _anim1.duration = 1.f;
- _anim1.fromValue = [NSNumber numberWithFloat:0.5];
- _anim1.toValue = [NSNumber numberWithFloat:1];
- _anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- _anim1.repeatCount = CGFLOAT_MAX;
- _anim1.autoreverses = YES;
- [ui_View.layer addAnimation:_anim1 forKey:nil];
- CABasicAnimation *_anim2 = [CABasicAnimation animationWithKeyPath:@"shadowRadius"];
- _anim2.duration = 1.f;
- _anim2.fromValue = [NSNumber numberWithFloat:10];
- _anim2.toValue = [NSNumber numberWithFloat:5];
- _anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- _anim2.repeatCount = CGFLOAT_MAX;
- _anim2.autoreverses = YES;
- [ui_View.layer addAnimation:_anim2 forKey:nil];
几个可以用来实现热门APP应用PATH中menu效果的几个方法
+(CABasicAnimation *)opacityForever_Animation:(float)time //永久闪烁的动画
{
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue=[NSNumber numberWithFloat:1.0];
animation.toValue=[NSNumber numberWithFloat:0.0];
animation.autoreverses=YES;
animation.duration=time;
animation.repeatCount=FLT_MAX;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
return animation;
}
+(CABasicAnimation *)opacityTimes_Animation:(float)repeatTimes durTimes:(float)time; //有闪烁次数的动画
{
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue=[NSNumber numberWithFloat:1.0];
animation.toValue=[NSNumber numberWithFloat:0.4];
animation.repeatCount=repeatTimes;
animation.duration=time;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
animation.autoreverses=YES;
return animation;
}
+(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x //横向移动
{
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
animation.toValue=x;
animation.duration=time;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
return animation;
}
+(CABasicAnimation *)moveY:(float)time Y:(NSNumber *)y //纵向移动
{
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
animation.toValue=y;
animation.duration=time;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
return animation;
}
+(CABasicAnimation *)scale:(NSNumber *)Multiple orgin:(NSNumber *)orginMultiple durTimes:(float)time Rep:(float)repeatTimes //缩放
{
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.fromValue=orginMultiple;
animation.toValue=Multiple;
animation.duration=time;
animation.autoreverses=YES;
animation.repeatCount=repeatTimes;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
return animation;
}
+(CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes //组合动画
{
CAAnimationGroup *animation=[CAAnimationGroup animation];
animation.animations=animationAry;
animation.duration=time;
animation.repeatCount=repeatTimes;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
return animation;
}
+(CAKeyframeAnimation *)keyframeAniamtion:(CGMutablePathRef)path durTimes:(float)time Rep:(float)repeatTimes //路径动画
{
CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path=path;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
animation.autoreverses=NO;
animation.duration=time;
animation.repeatCount=repeatTimes;
return animation;
}
+(CABasicAnimation *)movepoint:(CGPoint )point //点移动
{
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation"];
animation.toValue=[NSValue valueWithCGPoint:point];
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
return animation;
}
+(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount //旋转
{
CATransform3D rotationTransform = CATransform3DMakeRotation(degree, 0, 0,direction);
CABasicAnimation* animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.toValue= [NSValue valueWithCATransform3D:rotationTransform];
animation.duration= dur;
animation.autoreverses= NO;
animation.cumulative= YES;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
animation.repeatCount= repeatCount;
animation.delegate= self;
return animation;
}
实现view放大再缩小的效果
- - (void)viewDidLoad {
- [super viewDidLoad];
- layer=[CALayer layer];
- layer.frame=CGRectMake(50, 200, 50, 50);
- layer.backgroundColor=[UIColor orangeColor].CGColor;
- layer.cornerRadius=8.0f;
- CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
- animation.duration=4.0f;
- animation.autoreverses=NO;
- animation.repeatCount=1;
- animation.toValue=[NSNumber numberWithInt:-10];
- animation.fromValue=[NSNumber numberWithInt:200];
- animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- CABasicAnimation *animationZoomIn=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
- animationZoomIn.duration=2.0f;
- animationZoomIn.autoreverses=NO;
- animationZoomIn.repeatCount=1;
- animationZoomIn.toValue=[NSNumber numberWithFloat:1.56];
- animationZoomIn.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
- CABasicAnimation *animationZoomOut=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
- animationZoomOut.beginTime=2.0f;
- animationZoomOut.duration=2.0f;
- animationZoomOut.autoreverses=NO;
- animationZoomOut.repeatCount=1;
- animationZoomOut.toValue=[NSNumber numberWithFloat:.01];
- animationZoomOut.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
- CAAnimationGroup *group=[CAAnimationGroup animation];
- group.duration=4.0f;
- group.animations=[NSArray arrayWithObjects: animation, animationZoomIn, animationZoomOut,nil];
- group.removedOnCompletion=NO;
- group.fillMode=kCAFillModeForwards;
- [layer addAnimation:group forKey:nil];
- [self.view.layer addSublayer:layer];
- //layer.hidden=YES;
- }
CABasicAnimation animationWithKeyPath Types的更多相关文章
- CABasicAnimation animationWithKeyPath 一些规定的值
CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...
- 动画 CABasicAnimation animationWithKeyPath 一些规定的值
CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...
- 之一:CABasicAnimation - 基本动画
嗷呜嗷呜嗷呜 // 将视图作为属性方便后面执行多个不同动画 _myView = [[UIView alloc] init]; _myView.layer.position = CGPointMake( ...
- iOS技术博客(文摘)链接地址
objc系列译文(5.1):认识 TextKit 手把手教你配置苹果APNS推送服务 如何使用iOS Addressbook UIApplication深入研究 GCD倒计时 那些不能错过的Xco ...
- 动画浅析-CAAnimation和CATransition
出处: http://blog.csdn.net/mad2man/article/details/17260887 //动画播放完之后不恢复初始状态 baseAnimation.removed ...
- 基本动画CABasicAnimation - 完成之后闪回初始状态
基本动画CABasicAnimation 结束之后,默认闪回初始状态,那怎么解决呢? position需要设备两个属性: // MARK: - 结束后不要闪回去 anim.removedOnCompl ...
- CABasicAnimation的基本使用方法(移动·旋转·放大·缩小)
出处:http://blog.csdn.net/iosevanhuang/article/details/14488239 CABasicAnimation类的使用方式就是基本的关键帧动画. 所谓关键 ...
- iOS - CABasicAnimation
代码实例: [1] - (void)pulseClick { //!> 宽和高等比例转换 CABasicAnimation * pulse = [CABasicAnimation animati ...
- [转]CABasicAnimation用法
CABasicAnimation用法 CABasicAnimation 自己只有三个property fromValue toValue ByValue 当你创建一个 CABasicAni ...
随机推荐
- Java虚拟机JVM详解
一.JVM内存管理 1.1JVM运行时数据区 1.1.1程序计数器:记录当前线程正在执行的字节码指定的地址(行号) 为什么需要它:程序容易被打断 1.1.2虚拟机栈:存储当前线程运行方法时所需要的数据 ...
- Linux读写执行权限
Linux 将访问文件的用户分为 3 类,分别是文件的所有者,所属组(也就是文件所属的群组)以及其他人. 最常见的文件权限有 3 种,即对文件的读(用 r 表示). 写(用 w 表示). 执行(用 x ...
- group by 与 order by 一起使用的时候
select 后面的列+order by 后面的列 必须在group by 里面 也就是说 select 和 order by 后面的列是 group by 列的子集 而 select 和 order ...
- AI-人工智能/机器学习 seetafaceJNI
基于中科院seetaface2进行封装的JAVA人脸识别库,支持人脸识别.1:1比对.1:N比对. 项目介绍 基于中科院seetaface2进行封装的JAVA人脸识别算法库,支持人脸识别.1:1比对. ...
- HDU6534 Chika and Friendly Pairs(莫队,树状数组)
HDU6534 Chika and Friendly Pairs 莫队,树状数组的简单题 #include<bits/stdc++.h> using namespace std; cons ...
- Android NDK下载
http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin https://dl.google.com/android/rep ...
- 服务器控件调用JS函数
是服务器端控件,不能在JS里直接调用,但可以在aspx.cs 里写方法可以调用JS函数,比如JS方法名称是check(), function check() { alert(document.ge ...
- java常用加密算法
常用加密算法的Java实现(一) ——单向加密算法MD5和SHA 日期:2014/6/1 文:阿蜜果 1.Java的安全体系架构 1.1 Java的安全体系架构介绍 Java中为安 ...
- npm link的作用
语法: 1. 在一个包目录下npm link (把当前的包目录软连接到global folder里面,把二进制文件也软连接到global的bin里面 这个prefix可以用npm config ls ...
- Linux下编译安装Python-3.6.5
1.下载Python-3.6.5安装包 在Python官网(https://www.python.org/downloads/)下载对应的安装包,选择3.6.5的linux版本,如下图: 2.将安装包 ...