1. #define kDegreesToRadian(x) (M_PI * (x) / 180.0)
  2. #define kRadianToDegrees(radian) (radian*180.0)/(M_PI)
  3. - (void)viewDidLoad
  4. {
  5. [superviewDidLoad];
  6. self.title = @"测试动画";
  7. self.view.backgroundColor = [UIColorlightGrayColor];
  8. myTest1 = [[UILabelalloc]initWithFrame:CGRectMake(10, 100, 60, 40)];
  9. myTest1.backgroundColor = [UIColorblueColor];
  10. myTest1.textAlignment = NSTextAlignmentCenter;
  11. myTest1.text = @"张明炜";
  12. myTest1.textColor = [UIColorwhiteColor];
  13. [self.viewaddSubview:myTest1];
  14. //闪烁效果。
  15. //    [myTest1.layer addAnimation:[self opacityForever_Animation:0.5] forKey:nil];
  16. ///移动的动画。
  17. //    [myTest1.layer addAnimation:[self moveX:1.0f X:[NSNumber numberWithFloat:200.0f]] forKey:nil];
  18. //缩放效果。
  19. //    [myTest1.layer addAnimation:[self scale:[NSNumber numberWithFloat:1.0f] orgin:[NSNumber numberWithFloat:3.0f] durTimes:2.0f Rep:MAXFLOAT] forKey:nil];
  20. //组合动画。
  21. //    NSArray *myArray = [NSArray arrayWithObjects:[self opacityForever_Animation:0.5],[self moveX:1.0f X:[NSNumber numberWithFloat:200.0f]],[self scale:[NSNumber numberWithFloat:1.0f] orgin:[NSNumber numberWithFloat:3.0f] durTimes:2.0f Rep:MAXFLOAT], nil];
  22. //    [myTest1.layer addAnimation:[self groupAnimation:myArray durTimes:3.0f Rep:MAXFLOAT] forKey:nil];
  23. //路径动画。
  24. //    CGMutablePathRef myPah = CGPathCreateMutable();
  25. //    CGPathMoveToPoint(myPah, nil,30, 77);
  26. //    CGPathAddCurveToPoint(myPah, nil, 50, 50, 60, 200, 200, 200);//这里的是控制点。
  27. //    [myTest1.layer addAnimation:[self keyframeAnimation:myPah durTimes:5 Rep:MAXFLOAT] forKey:nil];
  28. //旋转动画。
  29. [myTest1.layeraddAnimation:[selfrotation:2degree:kRadianToDegrees(90) direction:1repeatCount:MAXFLOAT] forKey:nil];
  30. }
  31. #pragma mark === 永久闪烁的动画 ======
  32. -(CABasicAnimation *)opacityForever_Animation:(float)time
  33. {
  34. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];//必须写opacity才行。
  35. animation.fromValue = [NSNumber numberWithFloat:1.0f];
  36. animation.toValue = [NSNumber numberWithFloat:0.0f];//这是透明度。
  37. animation.autoreverses = YES;
  38. animation.duration = time;
  39. animation.repeatCount = MAXFLOAT;
  40. animation.removedOnCompletion = NO;
  41. animation.fillMode = kCAFillModeForwards;
  42. animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];///没有的话是均匀的动画。
  43. return animation;
  44. }
  45. #pragma mark =====横向、纵向移动===========
  46. -(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x
  47. {
  48. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///.y的话就向下移动。
  49. animation.toValue = x;
  50. animation.duration = time;
  51. animation.removedOnCompletion = NO;//yes的话,又返回原位置了。
  52. animation.repeatCount = MAXFLOAT;
  53. animation.fillMode = kCAFillModeForwards;
  54. return animation;
  55. }
  56. #pragma mark =====缩放-=============
  57. -(CABasicAnimation *)scale:(NSNumber *)Multiple orgin:(NSNumber *)orginMultiple durTimes:(float)time Rep:(float)repertTimes
  58. {
  59. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  60. animation.fromValue = Multiple;
  61. animation.toValue = orginMultiple;
  62. animation.autoreverses = YES;
  63. animation.repeatCount = repertTimes;
  64. animation.duration = time;//不设置时候的话,有一个默认的缩放时间.
  65. animation.removedOnCompletion = NO;
  66. animation.fillMode = kCAFillModeForwards;
  67. return  animation;
  68. }
  69. #pragma mark =====组合动画-=============
  70. -(CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes
  71. {
  72. CAAnimationGroup *animation = [CAAnimationGroupanimation];
  73. animation.animations = animationAry;
  74. animation.duration = time;
  75. animation.removedOnCompletion = NO;
  76. animation.repeatCount = repeatTimes;
  77. animation.fillMode = kCAFillModeForwards;
  78. return animation;
  79. }
  80. #pragma mark =====路径动画-=============
  81. -(CAKeyframeAnimation *)keyframeAnimation:(CGMutablePathRef)path durTimes:(float)time Rep:(float)repeatTimes
  82. {
  83. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  84. animation.path = path;
  85. animation.removedOnCompletion = NO;
  86. animation.fillMode = kCAFillModeForwards;
  87. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  88. animation.autoreverses = NO;
  89. animation.duration = time;
  90. animation.repeatCount = repeatTimes;
  91. return animation;
  92. }
  93. #pragma mark ====旋转动画======
  94. -(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount
  95. {
  96. CATransform3D rotationTransform = CATransform3DMakeRotation(degree, 0, 0, direction);
  97. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
  98. animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];
  99. animation.duration  =  dur;
  100. animation.autoreverses = NO;
  101. animation.cumulative = NO;
  102. animation.fillMode = kCAFillModeForwards;
  103. animation.repeatCount = repeatCount;
  104. animation.delegate = self;
  105. return animation;
  106. }

iOS简单动画效果:闪烁、移动、旋转、路径、组合的更多相关文章

  1. iOS各种动画效果

    ios各种动画效果 最普通动画: //开始动画 [UIView beginAnimations:nil context:nil];  //设定动画持续时间 [UIView setAnimationDu ...

  2. 原生JS封装简单动画效果

    原生JS封装简单动画效果 一致使用各种插件,有时候对原生JS陌生了起来,所以决定封装一个简单动画效果,熟悉JS原生代码 function animate(obj, target,num){ if(ob ...

  3. ios开发之--简单动画效果的添加

    记录一个简单的动画效果,自己写的,很简单,仅做记录. 附一个demo的下载地址: https://github.com/hgl753951/hglTest.git 代码如下: 1,准备 BOOL _i ...

  4. iOS添加到购物车的简单动画效果

    #pragma mark - 添加到购物车的动画效果 // huangyibiao - (void)addAnimatedWithFrame:(CGRect)frame { // 该部分动画 以sel ...

  5. iOS 转盘动画效果实现

    代码地址如下:http://www.demodashi.com/demo/11598.html 近期公司项目告一段落,闲来无事,看到山东中国移动客户端有个转盘动画挺酷的.于是试着实现一下,看似简单,可 ...

  6. iOS的动画效果类型及实现方法

    实现iOS漂亮的动画效果主要有两种方法, 一种是UIView层面的, 一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层也是使用CATransit ...

  7. iOS 帧动画之翻转和旋转动画

    记录两个比较简单的动画,一个是翻转的动画,一个是旋转的动画. 旋转动画: 1 [UIView animateWithDuration:3 animations:^{ if (formView) { f ...

  8. iOS开动画效果之──实现 pushViewController 默认动画效果

    在开发中,视图切换会常常遇到,有时我们不是基于导航控制器的切换,但实际开发中,有时需要做成push效果,下面将如何实现push和pop 默认动画效果代码实例: 一.push默认动画效果 CATrans ...

  9. jQuery之简单动画效果

    1. show()显示动画 语法:show(speed,callback) Number/String,Function speend为动画执行时间,单位为毫秒.也可以为slow",&quo ...

随机推荐

  1. Smart-image通过SoftReference提高性能

    文章导读: 文件介绍了常见的图片下载开源插件smart-image, 由于移动设备硬件受限,因此Android的相关app都要考虑到性能的关系, 所以很多的第三方插件都使用到了缓存cache技术,本人 ...

  2. 初次了解struts的action类

    Action类真正实现应用程序的事务逻辑,它们负责处理请求.在收到请求后,ActionServlet会为这个请求选择适当的Action 如果需要,创建Action的一个实例 调用Action的perf ...

  3. 天气类App原型制作分享-ColorfulClouds

    ColorfulClouds是一款界面精美的天气预报App,它可以准确预报降雨量.污染程度等.这款App最美的是它的首页天气插画,扁平精美,同时配上了适当的动效,把普通的天气变得漂亮有趣,十分吸引眼球 ...

  4. [bzoj1705] [Usaco2007 Nov]Telephone Wire 架设电话线

    正常DP.. f[i][j]表示前i个电线杆,把第i个电线杆高度改为j的最少总费用.设原来电线杆高度为h[] f[i][j]=min{ f[i-1][k]+C*|j-k|+(j-h[i])^2,(k& ...

  5. HDU1016 DFS+回溯(保存路径)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. 一 : springmvc常用注解

    springmvc常用注解详解1.@Controller在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层 ...

  7. 【CC2530入门教程-增强版】基础技能综合实训案例(基础版)-上位机源码

    [CC2530入门教程-增强版]基础技能综合实训案例(基础版)-上位机源码 广东职业技术学院  欧浩源 一.需求分析 按照指定参数打开串口,与测控终端建立数据传输通道,并根据应用要求实现程序逻辑,具体 ...

  8. 一步一步从原理跟我学邮件收取及发送 4.不同平台下的socket

    既然是面向程序员的文章那当然不能只说说原理,一定要有实际动手的操作.    其实作为我个人的经历来说,对于网络编程,这是最重要的一章! 作为一位混迹业内近20年的快退休的程序员,我学习过很多的开发语言 ...

  9. visual studio 打开微软MVC3示例MvcMusicStore的详细修改方法

    1.官方下载地址:http://mvcmusicstore.codeplex.com/ 2.直接打开项目后,引用中会有三个dll文件报错,分别是System.Web.MVC;System.Web.He ...

  10. github网站介绍、并使用git命令管理github(详细描述)

    本章学习: 1)熟悉github网站 2)通过git命令远程管理github, 3)git命令使用ssh key密钥无需输入账号密码 1.首先我们来熟悉github网站 1.1 注册github 登录 ...