转自: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.

  1. CABasicAnimation *theAnimation;
  2. theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
  3. theAnimation.delegate = self;
  4. theAnimation.duration = 1;
  5. theAnimation.repeatCount = 0;
  6. theAnimation.removedOnCompletion = FALSE;
  7. theAnimation.fillMode = kCAFillModeForwards;
  8. theAnimation.autoreverses = NO;
  9. theAnimation.fromValue = [NSNumber numberWithFloat:0];
  10. theAnimation.toValue = [NSNumber numberWithFloat:-60];
  11. [self.view.layer addAnimation:theAnimation forKey:@"animateLayer"];
  1. 我们可以通过animationWithKeyPath键值对的方式来改变动画
  2. animationWithKeyPath的值:
  3.  
  4. transform.scale = 比例轉換
  5. transform.scale.x = 闊的比例轉換
  6. transform.scale.y = 高的比例轉換
  7. transform.rotation.z = 平面圖的旋轉
  8. opacity = 透明度
  9.  
  10. margin
  11. zPosition
  12.  
  13. backgroundColor
  14.  
  15. cornerRadius
  16. borderWidth
  17.  
  18. bounds
  19. contents
  20.  
  21. contentsRect
  22. cornerRadius
  23. frame
  24.  
  25. hidden
  26.  
  27. mask
  28.  
  29. masksToBounds
  30. opacity
  31.  
  32. position
  33.  
  34. shadowColor
  35.  
  36. shadowOffset
  37.  
  38. shadowOpacity
  39. shadowRadius
  40. [self. ui_View.layer removeAllAnimations];
  41.  
  42. CABasicAnimation *pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  43. pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  44. pulse.duration = 0.5 + (rand() % 10) * 0.05;
  45. pulse.repeatCount = 1;
  46. pulse.autoreverses = YES;
  47. pulse.fromValue = [NSNumber numberWithFloat:.8];
  48. pulse.toValue = [NSNumber numberWithFloat:1.2];
  49. [self.ui_View.layer addAnimation:pulse forKey:nil];
  50.  
  51. // bounds
  52.  
  53. CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"bounds"];
  54. anim.duration = 1.f;
  55. anim.fromValue = [NSValue valueWithCGRect:CGRectMake(0,0,10,10)];
  56. anim.toValue = [NSValue valueWithCGRect:CGRectMake(10,10,200,200)];
  57. anim.byValue = [NSValue valueWithCGRect:self. ui_View.bounds];
  58. // anim.toValue = (id)[UIColor redColor].CGColor;
  59. // anim.fromValue = (id)[UIColor blackColor].CGColor;
  60.  
  61. anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  62. anim.repeatCount = 1;
  63. anim.autoreverses = YES;
  64.  
  65. [ui_View.layer addAnimation:anim forKey:nil];
  66. //cornerRadius
  67.  
  68. CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
  69. anim2.duration = 1.f;
  70. anim2.fromValue = [NSNumber numberWithFloat:0.f];
  71. anim2.toValue = [NSNumber numberWithFloat:20.f];
  72. anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  73. anim2.repeatCount = CGFLOAT_MAX;
  74. anim2.autoreverses = YES;
  75.  
  76. [ui_View.layer addAnimation:anim2 forKey:@"cornerRadius"];
  77.  
  78. //contents
  79.  
  80. CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"contents"];
  81. anim.duration = 1.f;
  82. anim.fromValue = (id)[UIImage imageNamed:@"1.jpg"].CGImage;
  83. anim.toValue = (id)[UIImage imageNamed:@"2.png"].CGImage;
  84. // anim.byValue = (id)[UIImage imageNamed:@"3.png"].CGImage;
  85. // anim.toValue = (id)[UIColor redColor].CGColor;
  86. // anim.fromValue = (id)[UIColor blackColor].CGColor;
  87.  
  88. anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  89. anim.repeatCount = CGFLOAT_MAX;
  90. anim.autoreverses = YES;
  91.  
  92. [ui_View.layer addAnimation:anim forKey:nil];
  93.  
  94. [ui_View.layer setShadowOffset:CGSizeMake(2,2)];
  95. [ui_View.layer setShadowOpacity:1];
  96. [ui_View.layer setShadowColor:[UIColor grayColor].CGColor];
  97. //
  98. CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowColor"];
  99. anim.duration = 1.f;
  100. anim.toValue = (id)[UIColor redColor].CGColor;
  101. anim.fromValue = (id)[UIColor blackColor].CGColor;
  102.  
  103. anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  104. anim.repeatCount = CGFLOAT_MAX;
  105. anim.autoreverses = YES;
  106.  
  107. [ui_View.layer addAnimation:anim forKey:nil];
  108.  
  109. CABasicAnimation *_anim = [CABasicAnimation animationWithKeyPath:@"shadowOffset"];
  110. _anim.duration = 1.f;
  111. _anim.fromValue = [NSValue valueWithCGSize:CGSizeMake(0,0)];
  112. _anim.toValue = [NSValue valueWithCGSize:CGSizeMake(3,3)];
  113.  
  114. _anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  115. _anim.repeatCount = CGFLOAT_MAX;
  116. _anim.autoreverses = YES;
  117.  
  118. [ui_View.layer addAnimation:_anim forKey:nil];
  119.  
  120. CABasicAnimation *_anim1 = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
  121. _anim1.duration = 1.f;
  122. _anim1.fromValue = [NSNumber numberWithFloat:0.5];
  123. _anim1.toValue = [NSNumber numberWithFloat:1];
  124.  
  125. _anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  126. _anim1.repeatCount = CGFLOAT_MAX;
  127. _anim1.autoreverses = YES;
  128.  
  129. [ui_View.layer addAnimation:_anim1 forKey:nil];
  130.  
  131. CABasicAnimation *_anim2 = [CABasicAnimation animationWithKeyPath:@"shadowRadius"];
  132. _anim2.duration = 1.f;
  133. _anim2.fromValue = [NSNumber numberWithFloat:10];
  134. _anim2.toValue = [NSNumber numberWithFloat:5];
  135.  
  136. _anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  137. _anim2.repeatCount = CGFLOAT_MAX;
  138. _anim2.autoreverses = YES;
  139.  
  140. [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放大再缩小的效果

  1. - (void)viewDidLoad {
  2.  
  3. [super viewDidLoad];
  4.  
  5. layer=[CALayer layer];
  6.  
  7. layer.frame=CGRectMake(50, 200, 50, 50);
  8.  
  9. layer.backgroundColor=[UIColor orangeColor].CGColor;
  10.  
  11. layer.cornerRadius=8.0f;
  12.  
  13. CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
  14.  
  15. animation.duration=4.0f;
  16.  
  17. animation.autoreverses=NO;
  18.  
  19. animation.repeatCount=1;
  20.  
  21. animation.toValue=[NSNumber numberWithInt:-10];
  22.  
  23. animation.fromValue=[NSNumber numberWithInt:200];
  24.  
  25. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  26.  
  27. CABasicAnimation *animationZoomIn=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
  28.  
  29. animationZoomIn.duration=2.0f;
  30.  
  31. animationZoomIn.autoreverses=NO;
  32.  
  33. animationZoomIn.repeatCount=1;
  34.  
  35. animationZoomIn.toValue=[NSNumber numberWithFloat:1.56];
  36.  
  37. animationZoomIn.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  38.  
  39. CABasicAnimation *animationZoomOut=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
  40.  
  41. animationZoomOut.beginTime=2.0f;
  42.  
  43. animationZoomOut.duration=2.0f;
  44.  
  45. animationZoomOut.autoreverses=NO;
  46.  
  47. animationZoomOut.repeatCount=1;
  48.  
  49. animationZoomOut.toValue=[NSNumber numberWithFloat:.01];
  50.  
  51. animationZoomOut.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  52.  
  53. CAAnimationGroup *group=[CAAnimationGroup animation];
  54.  
  55. group.duration=4.0f;
  56.  
  57. group.animations=[NSArray arrayWithObjects: animation, animationZoomIn, animationZoomOut,nil];
  58.  
  59. group.removedOnCompletion=NO;
  60.  
  61. group.fillMode=kCAFillModeForwards;
  62.  
  63. [layer addAnimation:group forKey:nil];
  64.  
  65. [self.view.layer addSublayer:layer];
  66.  
  67. //layer.hidden=YES;
  68.  
  69. }

CABasicAnimation animationWithKeyPath Types的更多相关文章

  1. CABasicAnimation animationWithKeyPath 一些规定的值

    CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...

  2. 动画 CABasicAnimation animationWithKeyPath 一些规定的值

    CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...

  3. 之一:CABasicAnimation - 基本动画

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

  4. iOS技术博客(文摘)链接地址

      objc系列译文(5.1):认识 TextKit 手把手教你配置苹果APNS推送服务 如何使用iOS Addressbook UIApplication深入研究 GCD倒计时 那些不能错过的Xco ...

  5. 动画浅析-CAAnimation和CATransition

      出处: http://blog.csdn.net/mad2man/article/details/17260887   //动画播放完之后不恢复初始状态 baseAnimation.removed ...

  6. 基本动画CABasicAnimation - 完成之后闪回初始状态

    基本动画CABasicAnimation 结束之后,默认闪回初始状态,那怎么解决呢? position需要设备两个属性: // MARK: - 结束后不要闪回去 anim.removedOnCompl ...

  7. CABasicAnimation的基本使用方法(移动·旋转·放大·缩小)

    出处:http://blog.csdn.net/iosevanhuang/article/details/14488239 CABasicAnimation类的使用方式就是基本的关键帧动画. 所谓关键 ...

  8. iOS - CABasicAnimation

    代码实例: [1] - (void)pulseClick { //!> 宽和高等比例转换 CABasicAnimation * pulse = [CABasicAnimation animati ...

  9. [转]CABasicAnimation用法

    CABasicAnimation用法   CABasicAnimation 自己只有三个property   fromValue  toValue  ByValue 当你创建一个 CABasicAni ...

随机推荐

  1. Java虚拟机JVM详解

    一.JVM内存管理 1.1JVM运行时数据区 1.1.1程序计数器:记录当前线程正在执行的字节码指定的地址(行号) 为什么需要它:程序容易被打断 1.1.2虚拟机栈:存储当前线程运行方法时所需要的数据 ...

  2. Linux读写执行权限

    Linux 将访问文件的用户分为 3 类,分别是文件的所有者,所属组(也就是文件所属的群组)以及其他人. 最常见的文件权限有 3 种,即对文件的读(用 r 表示). 写(用 w 表示). 执行(用 x ...

  3. group by 与 order by 一起使用的时候

    select 后面的列+order by 后面的列 必须在group by 里面 也就是说 select 和 order by 后面的列是 group by 列的子集 而 select 和 order ...

  4. AI-人工智能/机器学习 seetafaceJNI

    基于中科院seetaface2进行封装的JAVA人脸识别库,支持人脸识别.1:1比对.1:N比对. 项目介绍 基于中科院seetaface2进行封装的JAVA人脸识别算法库,支持人脸识别.1:1比对. ...

  5. HDU6534 Chika and Friendly Pairs(莫队,树状数组)

    HDU6534 Chika and Friendly Pairs 莫队,树状数组的简单题 #include<bits/stdc++.h> using namespace std; cons ...

  6. Android NDK下载

    http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin https://dl.google.com/android/rep ...

  7. 服务器控件调用JS函数

    是服务器端控件,不能在JS里直接调用,但可以在aspx.cs 里写方法可以调用JS函数,比如JS方法名称是check(), function check() {   alert(document.ge ...

  8. java常用加密算法

    常用加密算法的Java实现(一) ——单向加密算法MD5和SHA 日期:2014/6/1 文:阿蜜果 1.Java的安全体系架构 1.1           Java的安全体系架构介绍 Java中为安 ...

  9. npm link的作用

    语法: 1. 在一个包目录下npm link (把当前的包目录软连接到global folder里面,把二进制文件也软连接到global的bin里面  这个prefix可以用npm config ls ...

  10. Linux下编译安装Python-3.6.5

    1.下载Python-3.6.5安装包 在Python官网(https://www.python.org/downloads/)下载对应的安装包,选择3.6.5的linux版本,如下图: 2.将安装包 ...