1. 使用前
  2.  
  3. 需引入QuartzCore.framework, 并在相关文件中加入 #import "QuartzCore/QuartzCore.h"
  4.  
  5. 定义
  6.  
  7. shakeFeedbackOverlayUIImageView
  8.  
  9. 设置
  10.  
  11. self.shakeFeedbackOverlay.alpha = 0.0;
  12.  
  13. self.shakeFeedbackOverlay.layer.cornerRadius = 10.0; //设置圆角半径
  14.  
  15. 、图像左右抖动
  16.  
  17. CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  18.  
  19. shake.fromValue = [NSNumber numberWithFloat:-M_PI/];
  20.  
  21. shake.toValue = [NSNumber numberWithFloat:+M_PI/];
  22.  
  23. shake.duration = 0.1;
  24.  
  25. shake.autoreverses = YES; //是否重复
  26.  
  27. shake.repeatCount = ;
  28.  
  29. [self.shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];
  30.  
  31. self.shakeFeedbackOverlay.alpha = 1.0;
  32.  
  33. [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.alpha = 0.0; //透明度变0则消失 } completion:nil];
  34.  
  35. 摇晃动画2:

  {

CAKeyframeAnimation *frame=[CAKeyframeAnimation animation];

CGFloat left=-M_PI_2*0.125;

CGFloat right=M_PI_2*0.125;

frame.keyPath=@"postion";

frame.keyPath=@"transform.rotation";

frame.values=@[@(left),@(right),@(left)];

frame.duration = 0.5;

frame.repeatCount = 1000000;

[cell.layer addAnimation:frame forKey:nil];

  1. 、图像顺时针旋转
  2.  
  3. CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  4.  
  5. shake.fromValue = [NSNumber numberWithFloat:];
  6.  
  7. shake.toValue = [NSNumber numberWithFloat:*M_PI];
  8.  
  9. shake.duration = 0.8; shake.autoreverses = NO;
  10.  
  11. shake.repeatCount = ;
  12.  
  13. [self.shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];
  14.  
  15. self.shakeFeedbackOverlay.alpha = 1.0;
  16.  
  17. [UIView animateWithDuration:10.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.alpha = 0.0; } completion:nil];
  18.  
  19. 、图像关键帧动画
  20.  
  21. CAKeyframeAnimation *animation = [CAKeyframeAnimationanimation];
  22.  
  23. CGMutablePathRef aPath = CGPathCreateMutable();
  24.  
  25. CGPathMoveToPoint(aPath, nil, , );
  26.  
  27. CGPathAddCurveToPoint(aPath, nil, , , , , , );
  28.  
  29. animation.path = aPath;
  30.  
  31. animation.autoreverses = YES;
  32.  
  33. animation.duration = ;
  34.  
  35. animation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut];
  36.  
  37. animation.rotationMode = @"auto";
  38.  
  39. [ballView.layer addAnimation:animation forKey:@"position"];
  40.  
  41. 、组合动画 CAAnimationGroup
  42.  
  43. CABasicAnimation *flip = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.y"];
  44.  
  45. flip.toValue = [NSNumbernumberWithDouble:-M_PI];
  46.  
  47. CABasicAnimation *scale= [CABasicAnimationanimationWithKeyPath:@"transform.scale"];
  48.  
  49. scale.toValue = [NSNumbernumberWithDouble:];
  50.  
  51. scale.duration = 1.5;
  52.  
  53. scale.autoreverses = YES;
  54.  
  55. CAAnimationGroup *group = [CAAnimationGroupanimation];
  56.  
  57. group.animations = [NSArrayarrayWithObjects:flip, scale, nil];
  58.  
  59. group.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  60.  
  61. group.duration = ;
  62.  
  63. group.fillMode = kCAFillModeForwards;
  64.  
  65. group.removedOnCompletion = NO;
  66.  
  67. [ballView.layer addAnimation:group forKey:@"position"];
  68.  
  69. 、指定时间内旋转图片
  70.  
  71. //启动定时器 旋转光圈
  72.  
  73. - (void)startRotate
  74.  
  75. {
  76.  
  77. self.rotateTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(rotateGraduation) userInfo:nil repeats:YES];
  78.  
  79. }
  80.  
  81. //关闭定时器
  82.  
  83. - (void)stopTimer
  84.  
  85. {
  86.  
  87. if ([self.rotateTimer isValid])
  88.  
  89. {
  90.  
  91. [self.rotateTimer invalidate]; self.rotateTimer = nil;
  92.  
  93. }
  94.  
  95. }
  96.  
  97. //旋转动画
  98.  
  99. - (void)rotateGraduation
  100.  
  101. {
  102.  
  103. self.timeCount--;
  104.  
  105. if (self.timeCount == )
  106.  
  107. {
  108.  
  109. [self stopTimer];
  110.  
  111. // doSomeThing //旋转完毕 可以干点别的
  112.  
  113. self.timeCount = ;
  114.  
  115. }
  116.  
  117. else
  118.  
  119. {
  120.  
  121. //计算角度 旋转
  122.  
  123. static CGFloat radian = * (M_2_PI / );
  124.  
  125. CGAffineTransform transformTmp = self.lightImageView.transform;
  126.  
  127. transformTmp = CGAffineTransformRotate(transformTmp, radian);
  128.  
  129. self.lightImageView.transform = transformTmp;
  130.  
  131. };
  132.  
  133. }
  134.  
  135. 调用方法
  136.  
  137. self.timeCount = ; //动画执行25次
  138.  
  139. [self startRotate];

转载自:http://www.cnblogs.com/sell/archive/2013/02/01/2889013.html

iOS常用动画代码的更多相关文章

  1. IOS 制作动画代码和 设置控件透明度

    方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...

  2. ios常用动画

    // // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyri ...

  3. 【转】IOS 30多个iOS常用动画,带详细注释

    原文: http://blog.csdn.net/zhibudefeng/article/details/8691567 CoreAnimationEffect.h 文件 // CoreAnimati ...

  4. iOS常用动画-b

    CoreAnimationEffect.h //  CoreAnimationEffect // //  Created by VincentXue on 13-1-19. //  Copyright ...

  5. 30多种iOS常用动画

    转自:http://blog.csdn.net/zhibudefeng/article/details/8691567 // //  CoreAnimationEffect.h //  CoreAni ...

  6. iOS常用动画 类封装

    //这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...

  7. iOS 常用开源代码整理

    本文章不定期整理. 1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功 ...

  8. iOS常用的代码块整理

    strong @property (nonatomic,strong) <#Class#> *<#object#>; weak @property (nonatomic,wea ...

  9. IOS 常用功能代码

    1. 关闭/隐藏键盘 resignFirstResponder 响应view的方法 -(IBAction)fname:(id)sender{ [sender resignFirstResponder] ...

随机推荐

  1. Java [Leetcode 88]CMerge Sorted Array

    题目描述: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. N ...

  2. LeetCode:Sort List

    Title: Sort a linked list in O(n log n) time using constant space complexity. 思路:考虑快速排序和归并排序,但是我的快速排 ...

  3. 利用ffmpeg解码h264流的代码

    这里也直接给出代码: h264dec.h: #pragma once #include "tdll.h" #include "avcodec.h" #inclu ...

  4. 【ASP.NET】编程点滴 :ASP.NET身份验证

    ASP.NET实际开发中身份验证 是一个不可回避的问题.在相当一段长的时间内,由于不求甚解,我对这个话题似懂非懂.今天就对它做个简单的小结. Authentication and Authorizat ...

  5. Android:真机调试,不显示logcat的解决方案

    有时做开发的时候,用真机测试,总是看不到logcat信息 .原因是系统默认关闭了log,需要将其打开. 解决办法如下:   在拨号界面输入*#*#2846579#*#* ,然后系统会自动弹出一个菜单, ...

  6. SharePoint 2010 列表项事件接收器 ItemAdded 的使用方法

    列表项事件处理器是继承于Microsoft.SharePoint.SPItemEventReceiver的类,Microsoft.SharePoint.SPItemEventReceiver类提供了许 ...

  7. 链表的倒数第K个节点

    题目:输入一个链表,输出该链表中倒数第K个节点.为了符合大多数人的习惯,本题从1开始计数,即链表的尾节点是倒数第1个结点. package com.edu; class LinkNode{ //定义一 ...

  8. Easy steps to create a System Tray Application with C# z

    Hiding the C# application to the system tray is quiet straight forward. With a few line of codes in ...

  9. 按钮点击WIN8 磁贴效果

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  10. HDU5731 Solid Dominoes Tilings 状压dp+状压容斥

    题意:给定n,m的矩阵,就是求稳定的骨牌完美覆盖,也就是相邻的两行或者两列都至少有一个骨牌 分析:第一步: 如果是单单求骨牌完美覆盖,请先去学基础的插头dp(其实也是基础的状压dp)骨牌覆盖 hiho ...