Main.storyboard

ViewController.m

//

//  ViewController.m

//  8A02.核心动画 - CAKeyframeAnimation

//

//  Created by huan on 16/2/4.

//  Copyright © 2016年 huanxi. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

//添加一个圆

CGFloat screenW = [UIScreen mainScreen].bounds.size.width;

UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenW, screenW)];

circleView.backgroundColor = [UIColor yellowColor];

//设置圆角

circleView.layer.cornerRadius = screenW * 0.5;

[self.view addSubview:circleView];

//把图片移到顶部

[self.view bringSubviewToFront:self.imageView];

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

//学习帧动画

//创建一个帧动画

CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];

animation.keyPath = @"position";

//设置动画执行路径 指定四个点

NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(50, 50)];

NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(250, 50)];

NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(250, 250)];

NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(50, 250)];

//数组第一个是"开始状态" 最后一个是“结束状态”

animation.values = @[value1, value2, value3, value4, value1];

//设置时间

animation.duration = 3;

//设置动画节奏

//    kCAMediaTimingFunctionEaseIn 先慢后快

//    kCAMediaTimingFunctionEaseOut 先慢后快

//    kCAMediaTimingFunctionEaseOut 线性匀速

//    kCAMediaTimingFunctionEaseInEaseOut 中间快两边慢

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

#warning 内部的path的优先级大于values优先级

//设置路径

CGMutablePathRef path = CGPathCreateMutable();

CGFloat screenW = [UIScreen mainScreen].bounds.size.width;

CGPathAddEllipseInRect(path, NULL, CGRectMake(0, 0, screenW, screenW));

animation.path = path;

//c语言的数据类型,如果create/copy/retain 创建要释放

//添加动画

[self.imageView.layer addAnimation:animation forKey:nil];

}

@end

结果

核心动画(CAKeyframeAnimation)的更多相关文章

  1. 核心动画 - CAKeyframeAnimation 简单应用

    核心动画: 登录按钮的抖动效果: CAKeyframeAnimation * kfAnimation = [CAKeyframeAnimation animationWithKeyPath:@&quo ...

  2. IOS 核心动画(Core Animation)

    Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它 能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就 可以实现非常强大的功能. Core ...

  3. AJ学IOS(40)UI之核心动画_抖动效果_CAKeyframeAnimation

    AJ分享,必须精品 效果: 效果一: 效果二: 代码: // // NYViewController.m // 图片抖动 // // Created by apple on 15-5-8. // Co ...

  4. IOS 核心动画之CAKeyframeAnimation - iBaby

    - IOS 核心动画之CAKeyframeAnimation - 简单介绍 是CApropertyAnimation的子类,跟CABasicAnimation的区别是:CABasicAnimation ...

  5. iOS:核心动画之关键帧动画CAKeyframeAnimation

    CAKeyframeAnimation——关键帧动画 关键帧动画,也是CAPropertyAnimation的子类,与CABasicAnimation的区别是: –CABasicAnimation只能 ...

  6. 核心动画(CAKeyframeAnimation,CABasicAnimation)

    一,核心动画常用的三种例子 view的核心动画其体现就是把view按照指定好的路径进行运动,针对的是view的整体. [view.layer addAnimation:动画路径 forKey:@“绑定 ...

  7. CoreAnimation 核心动画 / CABasicAnimation/ CAKeyframeAnimation

    - (void)createBaseAnimation{ //基础动画 CABasicAnimation *animation = [CABasicAnimation animation]; anim ...

  8. ios开发核心动画五:图标抖动效果--CAKeyframeAnimation

    #import "ViewController.h" #define angle2Rad(angle) ((angle) / 180.0 * M_PI) @interface Vi ...

  9. iOS开发UI篇—核心动画(关键帧动画)

    转自:http://www.cnblogs.com/wendingding/p/3801330.html iOS开发UI篇—核心动画(关键帧动画) 一.简单介绍 是CApropertyAnimatio ...

随机推荐

  1. robotframework ride安装

    之前在python3.3.5的环境下一直无法找到匹配的wxPython版本,只能再装了一个python2.7,后面在2.7的环境下重新安装了robotframework和ride,结果还是无法启动ri ...

  2. [整理]Matlab之中心平滑滤波

    滑动平均(moving average):在地球物理异常图上,选定某一尺寸的窗口,将窗口内的所有异常值做算术平均,将平均值作为窗口中心点的异常值.按点距或线距移动窗口,重复此平均方法,直到对整幅图完成 ...

  3. MSSQL附加数据库5120错误(拒绝访问)处理方法

    一. 右键需要附加的数据库文件,弹出属性对话框,选择安全标签页. 找到Authenticated Users用户名. 如未找到,进行Authenticated Users用户名的添加. 二. 添加Au ...

  4. CSS布局设计

    CSS布局设计: (1)固定布局:各个部分采用固定宽度的页面布局. (2)流式布局:通过定义模块和模块间距的百分比的方式来实现.缺点是会自动缩放,影响图片的美观. (3)响应式布局:页面可以用户的设备 ...

  5. Android学习---ListView的点击事件,simpleAdapter和arrayadapter,SimpleCursoAdapter的原理和使用

    如题,本文将介绍 listview的点击事件,simpleAdapter和arrayadapter的原理和使用. 1.ListView的注册点击事件 //注册点击事件 personListView.s ...

  6. jQuery Mobile 中创建按钮

    在 jQuery Mobile 中创建按钮 jQuery Mobile 中的按钮可通过三种方法创建: 使用 <button> 元素 使用 <input> 元素 使用 data- ...

  7. [转] Oracle sql 查询突然变慢 -- 案例分析

    转自:http://jingyan.baidu.com/article/8275fc868ce57946a03cf692.html 一条sql突然执行变慢,耗时9秒,应用是不能改的,只能从数据库方面下 ...

  8. VS2010+C#+AutoCAD2008时断点调试功能无效的处理方法

    把acad.exe.config文件修改为:------------------------------------------------------------------------------ ...

  9. 约瑟夫环问题(c++)

    #include <iostream> struct node{ int payload; node* next; node(int payload){this->payload = ...

  10. 选择流程—— switch if else结构

    一.switch switch(表达式){ case 常量1: 语句; break; case 常量2: 语句; break; … default; 语句; } 例题:运用switch结构实现购物管理 ...