转自: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]; // 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; }
复制代码

转载于:https://www.cnblogs.com/fyongbetter/p/5633148.html

iOS 动画(三)CABasicAnimation animationWithKeyPath 一些规定的值相关推荐

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

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

  2. iOS动画详解(学习动画看这一篇就够了)

    2019独角兽企业重金招聘Python工程师标准>>> 原文出处:wu大维 动效设计一直是iOS平台的优势,良好的动效设计可以很好地提升用户体验.而动画则是动效的基础支撑.本动画将从 ...

  3. iOS 动画之CoreAnimation(CALayer)

    CoreAnimation基本介绍 CoreAnimation动画位于iOS框架的Media层 CoreAnimation动画实现需要添加QuartzCore.Framework CoreAnimat ...

  4. iOS动画系列之五:基础动画之缩放篇旋转篇Swift+OC

    这一篇主要介绍基础动画之缩放和旋转.这些基本操作分享完之后,我想想可以找个稍微复杂一点点的动画做做啦. 这篇继续基础篇,分享一下缩放和旋转.因为整体思路和平移基本上没有变化,加上源代码里面也有OC版本 ...

  5. iOS 动画基础总结篇

    iOS 动画基础总结篇   动画的大体分类(个人总结可能有误) 分类.png UIView 动画 属性动画 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  6. iOS动画-从UIView到Core Animation

    首先,介绍一下UIView相关的动画. UIView普通动画: [UIView beginAnimations: context:];[UIView commitAnimations]; 动画属性设置 ...

  7. iOS动画-CAAnimation使用详解

    理解了隐式动画后,显式动画就更加通俗易懂了.区别于隐式动画的特点,显式动画就是需要我们明确指定类型.时间等参数来实现效果的动画.除此之外,我们也可以创建非线性动画,比如沿着任意一条曲线运动等: 我们平 ...

  8. iOS 动画 - 从不会到熟练应用

    原文链接:http://www.jianshu.com/p/3f48fabaca19 一个很好的讲动画的文章, 基本涵盖了 80% 的动画知识点. -- 由 抱紧我的小鲤鱼 分享 原创内容,转载请注明 ...

  9. iOS 动画实战之钓鱼小游戏

    点击上方"iOS开发",选择"置顶公众号" 关键时刻,第一时间送达! 如何快速成长为优秀程序员?高薪程序员必备工具!(点击进入) 前言 最近写了一款钓鱼小游戏, ...

最新文章

  1. fgo日服服务器维护,【FGO日服】活动维护通知(1/10)
  2. Linux常用运维命令笔记
  3. 查看MySQL的当前日期
  4. 第一百二十八期:推荐几个IDEA插件,Java开发者撸码利器,你get到了吗
  5. 万万没想到,JVM内存结构的面试题可以问的这么难?
  6. HTML5 figure元素
  7. github设置仓库可见性 私人仓库设置他人协作/可见
  8. 强悍的命令行 —— less(与 more、cat 的区别)
  9. 讨论CGContextDrawImage
  10. 苹果uwb_苹果发布会前瞻:iPhone12还得再等等 UWB或成最大惊喜
  11. 白盒测试-条件组合覆盖
  12. 《数据结构》网课 邓俊辉 习题详细解析(第七章:二叉搜索树)
  13. 周轶璐教授:服务好医生,如何更全面地了解数据、利用数据?
  14. MaxEnt运行错误
  15. linux如何给脚本等创建一个桌面启动图标
  16. 在爱奇艺的B站大佬,有点强
  17. redis分布式锁与zk分布式锁的对比
  18. 单片机 P0口、P1口 寄存器和引脚的不同
  19. Android Studio 用WIFI无线调试adb (3种方法)
  20. 集群服务器session共享

热门文章

  1. httpd服务配置(未完待续)
  2. Eagle个人博客系统
  3. GDB 调试命令讲解 2-转
  4. linux下启动Oracle服务和监听程序
  5. [GIT] warning: LF will be replaced by CRLF问题解决方法
  6. 自己做的一个简历网页,有很多bug解决不了,有没有大神帮我看看
  7. 12python(第十二天日记)
  8. 【1】mongoDB 的安装及启动
  9. C++ 中dynamic_castlt;gt;的用法
  10. C# 索引器的简单例子