1,CAKeyframeAnimation介绍

CAKeyframeAnimation可以实现关键帧动画,这个类可以实现某一属性按照一串的数值进行动画,就像是一帧一帧的制作出来一样。
 
2,使用样例(设置五个关键点坐标,图片依次按关键点移动)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

//

//  ViewController.swift

//  CAKeyframeAnimation

//

//  Created by Wengrp on 16/12/1.

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

//

import UIKit

class ViewController: UIViewController {

var imageView: UIView!

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

let animation = CAKeyframeAnimation(keyPath: "position")

//设置5个位置点

let p1 = CGPointMake(100.0, 100.0)

let p2 = CGPointMake(300, 100.0)

let p3 = CGPointMake(100.0, 400)

let p4 = CGPointMake(300, 400)

let p5 = CGPointMake(150, 200)

//赋值

animation.values = [NSValue(CGPoint: p1), NSValue(CGPoint: p2),

NSValue(CGPoint: p3), NSValue(CGPoint: p4), NSValue(CGPoint: p5)]

//每个动作的时间百分比

animation.keyTimes = [NSNumber(float: 0.0), NSNumber(float: 0.4),

NSNumber(float: 0.6), NSNumber(float: 0.8), NSNumber(float: 1.0), ]

animation.delegate = self

animation.duration = 6.0

imageView = UIView(frame: CGRectMake(100, 100, 100, 100))

imageView.backgroundColor = UIColor.cyanColor()

imageView.layer.addAnimation(animation, forKey: "Image-Move")

self.view.addSubview(imageView)

}

override func animationDidStart(anim: CAAnimation) {

print("动画开始")

}

override func animationDidStop(anim: CAAnimation, finished flag: Bool) {

print("动画结束")

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

3,可以设置动画代理,监听开始和结束动作

1
2
3
4
5
6
7
8
9
animation.delegate = self
 
override func animationDidStart(anim: CAAnimation!) {
    println("动画开始")
}
 
override func animationDidStop(anim: CAAnimation!, finished flag: Bool) {
    println("动画结束")
}

PS:苹果官网API - CAKeyframeAnimation

Swift - 使用CAKeyframeAnimation实现关键帧动画的更多相关文章

  1. 核心动画基础动画(CABasicAnimation)关键帧动画

    1.在iOS中核心动画分为几类: 基础动画(CABasicAnimation) 关键帧动画(CAKeyframeAnimation) 动画组(CAAnimationGroup) 转场动画(CATran ...

  2. IOS开发-属性动画和关键帧动画的使用

    CAMediaTiming是一个协议(protocol),CAAnimation是所有动画类的父类,但是它不能直接使用,应该使用它的子类. 继承关系: CoreAnmiation 核心动画 简写CA ...

  3. Core Animation 动画的使用:关键帧动画、基础动画、动画组

    首先让我们了解下什么是 Core Animation,Core Animation 为核心动画,他为图形渲染和动画提供了基础.使用核心动画,我们只需要设置起点.终点.关键帧等一些参数,剩下的工作核心动 ...

  4. ios基础动画、关键帧动画、动画组、转场动画等

    概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互式绘图,如何通过核心动画创建基础动画.关键帧动画 ...

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

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

  6. core Animation之CAKeyframeAnimation(关键帧动画)

    CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSA ...

  7. IOS第18天(6,CAKeyframeAnimation关键帧动画)

    ******* #import "HMViewController.h" @interface HMViewController () @property (weak, nonat ...

  8. [Xcode 实际操作]九、实用进阶-(20)创建位移关键帧动画:通过添加运动关键点制作位移动画

    目录:[Swift]Xcode实际操作 本文将演示如何通过添加运动关键点的方式,来制作位移动画 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIK ...

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

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

随机推荐

  1. Matlab2015基本语句语法04

    1. 输入.输出.格式化输出 1) 读入数据:input >>number: num=input('Give me your number: '); >>string: str ...

  2. 理解Cookie和Session机制(转)

    目录[-] Cookie机制 什么是Cookie 记录用户访问次数 Cookie的不可跨域名性 Unicode编码:保存中文 BASE64编码:保存二进制图片 设置Cookie的所有属性 Cookie ...

  3. 关于line-height

    line-height不允许负值,给定值之后会根据font-size计算行高,line-height指定的行高是行高最小值,设置height可以增大行高 line-height的计算:以px为例,li ...

  4. 11月7日上午PHP会话控制(session和cookie)、跨页面传值

    1.session  登录上一个页面以后,长时间没有操作,刷新页面以后需要重新登录. 特点:(1)session是存储在服务器:   (2)session每个人(登陆者)存一份: (3)session ...

  5. (转)MySQL索引原理及慢查询优化

    转自美团技术博客,原文地址:http://tech.meituan.com/mysql-index.html 建索引的一些原则: 1.最左前缀匹配原则,非常重要的原则,mysql会一直向右匹配直到遇到 ...

  6. Django基础,Day9 - 静态文件目录与路径设置说明(eg. images, JavaScript, CSS)

    静态文件路径设置官方说明 1. Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS. 2. In ...

  7. css 实现三角形 实现过程

     1.纯色的全等的三角形实现 下面的就是实际实现  没有宽高 只有边框 都是透明 根据箭头的方向 给边框方法加颜色  比如需要像右箭头 只需要给border-right-color:颜色值; 即可 c ...

  8. php5 数据类型

    一.PHP主要有一下几种数据类型 String(字符串), Integer(整型), Float(浮点型), Boolean(布尔型), Array(数组), Object(对象), NULL(空值) ...

  9. 守护进程demon.c

    1 #include <stdio.h> #include <unistd.h> #include <errno.h> #include <time.h> ...

  10. 大组合数:Lucas定理

    最近碰到一题,问你求mod (p1*p2*p3*……*pl) ,其中n和m数据范围是1~1e18 , l ≤10 , pi ≤ 1e5为不同的质数,并保证M=p1*p2*p3*……*pl ≤ 1e18 ...