#import "ViewController.h"

#define angle2Rad(angle) ((angle) / 180.0 * M_PI)

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageV; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { /**
1:UIBezierPath:是绘制路径的类,moveToPoint设置起点,addLineToPoint,从起点绘制一条路径,在执行addLineToPoint,则从终点作为起点,在绘制一条路径,要转为CGPath
*
*/
//1.创建动画对象
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation]; anim.duration = ; UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(, )];
[path addLineToPoint:CGPointMake(, )];
[path addLineToPoint:CGPointMake(, )]; anim.keyPath = @"position";
anim.path = path.CGPath; [self.imageV.layer addAnimation:anim forKey:nil]; } //图标抖动
- (void)icon { //1.创建动画对象
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation]; //2.设置属性值
/**1:keyPath为layear下的属性的keypath路径 2:values是一个数组,在values数组里定义的对象都会产生动画效果,让图标先向左移动-3弧度,再动画回来移动到3弧度,在动画移动到-3,无限重复
2:也可以设置动画的翻转效果:anim.values = @[@(angle2Rad(-3)),@(angle2Rad(3))],anim.autoreverses,这样执行完values里的动画到3弧度后,还会动画回来继续重复,否则不会产生动画
3:再把动画添加到layear层上,核心动画都是作用砸layear层上
*
*/
anim.keyPath = @"transform.rotation";
anim.values = @[@(angle2Rad(-)),@(angle2Rad()),@(angle2Rad(-))]; //3.设置动画执行次数
anim.repeatCount = MAXFLOAT; anim.duration = 0.5; //anim.autoreverses = YES; [self.imageV.layer addAnimation:anim forKey:nil]; }
@end

1.帧动画介绍:

CAKeyframeAnimation它可以在多个值之间进行动画.

设置多值之间的属性为:

后面是一个数组,就是要设置的多个值.

anim.values = @[];

它还可以根据一个路径做动画.

anim.path = 自己创建的路径.

2.图片抖动思路:

其实就是做一个左右旋转的动画.先让它往左边旋转-5,再往右边旋转5度,再从5度旋转到-5度.

就会有左右摇摆的效果了.

具体实现代码

创建帧动画

CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

设置动画属性为旋转

anim.keyPath = @"transform.rotation";

设置属性值为多个属性

anim.values = @[@(angle2radio(-5)),@(angle2radio(5)),@(angle2radio(-5))];

设置动画执行次数

anim.repeatCount = MAXFLOAT;

添加动画

[_imageView.layer addAnimation:anim forKey:nil];

3.根据圆形的路径做移动的效果.

创建路径

UIBezierPath *path = [UIBezierPath

bezierPathWithOvalInRect:CGRectMake(50, 50, 100, 100)];

[path addLineToPoint:CGPointMake(200, 500)];

把路径设为动画的属性

anim.path = path.CGPath;

ios开发核心动画五:图标抖动效果--CAKeyframeAnimation的更多相关文章

  1. ios开发核心动画五:转场动画

    #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutl ...

  2. IOS开发核心动画六:动画组

    #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutl ...

  3. iOS开发-核心动画随笔

    核心动画可以让View旋转,缩放,平移(主要是操作View的layer(层)属性)但是核心动画改变的位置不是真实的位置,一切都是假象所以有时候要用到其他动画,如UIView本来封装的动画,还有定时器 ...

  4. ios开发核心动画七:核心动画与UIView动画的区别

    /** UIView与核心动画区别?(掌握) 1.核心动画只作用在layer. 2.核心动画看到的都是假像,它并没有去修改UIView的真实位置. 什么时候使用核心动画? 1.当不需要与用户进行交互, ...

  5. ios开发核心动画三:隐式动画与时钟效果

    一:隐式动画 #import "ViewController.h" @interface ViewController () /** <#注释#> */ @proper ...

  6. iOS学习——核心动画

    iOS学习——核心动画 1.什么是核心动画 Core Animation(核心动画)是一组功能强大.效果华丽的动画API,无论在iOS系统或者在你开发的App中,都有大量应用.核心动画所在的位置如下图 ...

  7. iOS开发之动画编程的几种方法

    iOS开发之动画编程的几种方法 IOS中的动画总结来说有五种:UIView<block>,CAAnimation<CABasicAnimation,CATransition,CAKe ...

  8. IOS QuartzCore核心动画框架

    IOS QuartzCore核心动画框架 核心动画框架 使用核心动画需要引入的框架:#import CALayer: CoreAnimation CALayer就是UIView上的图层,很多的CALa ...

  9. iOS学习——核心动画之Layer基础

    iOS学习——核心动画之Layer基础 1.CALayer是什么? CALayer我们又称它叫做层.在每个UIView内部都有一个layer这样一个属性,UIView之所以能够显示,就是因为它里面有这 ...

随机推荐

  1. [ES6] Extends class in ES6 vs ES5 subclass

    ES6 class with extends and super: class Tree { constructor(size = ', leaves = {spring: 'green', summ ...

  2. [AngularFire] Angular File Uploads to Firebase Storage with Angular control value accessor

    The upload class will be used in the service layer. Notice it has a constructor for file attribute, ...

  3. hdu 1384 Intervals (差分约束)

    /* 给你 n 个区间 [Ai, Bi],要求从每一个区间中至少选出 Ci 个数出来组成一个序列 问:满足上面条件的序列的最短长度是多少? 则对于 不等式 f(b)-f(a)>=c,建立 一条 ...

  4. php7 兼容 MySQL 相关函数

    php7 兼容 MySQL 相关函数 PHP7 废除了 ”mysql.dll” ,推荐使用 mysqli 或者 pdo_mysql http://PHP.net/manual/zh/mysqlinfo ...

  5. LinearLayout-margin不起作用的处理

    1.如果LinearLayout中使用android:layout_marginRight不起作用,通过测试原来在android2.x中,如果一个控件中有android:layout_gravity属 ...

  6. 转:Java的一道面试题----静态变量初始化过程

    public class Test{ private static Test tester = new Test(); //step 1 private static int count1; //st ...

  7. 利用js 获取本日 本周 本月时间代码

    function showToDay() { var Nowdate=new Date(); M=Number(Nowdate.getMonth())+1 alert(Nowdate.getMonth ...

  8. JS实践与写博客-序

    大二的时候,就开始接触JavaScript了. 当时学了1年多,主要是认真看了一本JavaScript的入门书籍,了解了JavaScript大致怎么回事.在独自做Web项目的时候,用的都是JavaSc ...

  9. 03002_MySQL数据库的安装和配置

    1.MySQL的安装 (1)下载mysql-5.5.49-win32.msi, 链接:MySQL安装包下载 密码:geqh : (2)打开下载的MySQL安装文件mysql-5.5.27-win32. ...

  10. POJ 3045 Cow Acrobats (最大化最小值)

    题目链接:click here~~ [题目大意] 给你n头牛叠罗汉.每头都有自己的重量w和力量s,承受的风险数rank就是该牛上面全部牛的总重量减去该牛自身的力量,题目要求设计一个方案使得全部牛里面风 ...