转自: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
zPositionbackgroundColorcornerRadius
borderWidthbounds
contentscontentsRect
cornerRadius
framehiddenmaskmasksToBounds
opacitypositionshadowColorshadowOffsetshadowOpacity
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];// boundsCABasicAnimation *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];
//cornerRadiusCABasicAnimation *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"];//contentsCABasicAnimation *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;}
复制代码

转载于:https://www.cnblogs.com/W-Kr/p/5095247.html

CABasicAnimation animationWithKeyPath Types相关推荐

  1. iOS 动画(三)CABasicAnimation animationWithKeyPath 一些规定的值

    转自:http://www.cnblogs.com/pengyingh/articles/2379631.html CABasicAnimation animationWithKeyPath 一些规定 ...

  2. 之一:CABasicAnimation - 基本动画

    嗷呜嗷呜嗷呜 1 // 将视图作为属性方便后面执行多个不同动画 2 _myView = [[UIView alloc] init]; 3 _myView.layer.position = CGPoin ...

  3. 贝塞尔结合CAShapeLayer绘制路线,CABasicAnimation实现的小动画

    最近项目需求,做的一个标识正在直播的小动画,代码如下: #import "YGIsOnLiveAnmationView.h" @interface YGIsOnLiveAnmati ...

  4. CABasicAnimation 动画组合

    使用CAAnimationGroup类进行复数动画的组合.代码如下: /* 动画1(在X轴方向移动) */ CABasicAnimation *animation1 =     [CABasicAni ...

  5. iOSCoreAnimation动画系列教程(一):CABasicAnimation【包会】

    本文的最新版本已经发布在简书[编程小翁]上,强烈建议到上查看简书,[点击这里跳转]. 在iOS中,图形可分为以下几个层次: 越上层,封装程度越高,动画实现越简洁越简单,但是自由度越低:反之亦然.本文着 ...

  6. CABasicAnimation使用总结

    2019独角兽企业重金招聘Python工程师标准>>> 实例化 使用方法animationWithKeyPath:对 CABasicAnimation进行实例化,并指定Layer的属 ...

  7. iOS动画:UIView动画和CALayer动画(CABasicAnimation、CAKeyframeAnimation的使用)

    iOS中的动画有两种实现方式,一种是UIView来实现动画,另一种动画是通过CALayer来实现,下面介绍两种动画的简单实现: 一.UIView动画的实现 UIView使用Context来实现动画 关 ...

  8. CABasicAnimation x y z 轴旋转动画

    x轴旋转: CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"tra ...

  9. CABasicAnimation动画

    使用CABasicAnimation动画: CALayer *znzLayer; = [[CALayer alloc]init]; //创建不断该表CALayer的transform属性动画CABas ...

  10. CABasicAnimation

    CABasicAnimation 自己只有三个property   fromValue  toValue  ByValue 当你创建一个 CABasicAnimation 时,你需要通过-setFro ...

最新文章

  1. 生物信息学常见数据格式 • fasta • fastq • gff/gtf
  2. 试图使用removebg工具的在线网站去除图片背景时遇到的错误
  3. 禅道类似软件_软件测试工程师都在用哪些测试工具
  4. php公众获取用户信息,PHP--通过公众号获取用户微信信息
  5. 计算机f盘的东西能删不,电脑清理文件不小心把F盘文件删除怎么办
  6. 超威主板关闭超线程教程
  7. Python爬虫从0到1 | 入门实战:360翻译 ——requests库之POST方法(新手必看,保姆级别教学)
  8. 基于SSM实现高校应届生就业管理系统
  9. 五分钟学会python_果粉有福了!5分钟学会用Python统计自己最爱听的音乐
  10. UG NX 12 同步建模技术
  11. 2018.12.6 python基础学习——列表的魔法(一)
  12. 【爬虫】python使用selenium抓取淘宝中的商品数据
  13. uni-app使用iconfont
  14. nyist--周期串
  15. SQLDER--工具参数--中英文对照
  16. linux sh命令简述
  17. 打开IE浏览器自动跳转到Edge浏览器
  18. 带你走进与千万数据通信者共成长的“家园”
  19. 6.10数藏汇总|国家队入场数字藏品,成为风向标?
  20. 用数据说谎How to Lie with Data

热门文章

  1. 阿里云:linux 一键安装web环境
  2. [C++] C/C++结构体的区别
  3. 浅谈:如何加快本本的开机时间
  4. Cannot declare member function ...to have static linkage错误
  5. Position与localPosition的区别
  6. Linux系统编程 -- 可执行文件结构与进程在内存中的分布
  7. python执行request请求
  8. 课程《设计模式之美》笔记之关于java四大特性
  9. 【渝粤题库】广东开放大学 建筑工程概预算 形成性考核
  10. 【浙江大学PAT真题练习乙级】1002 写出这个数(20分) 真题解析