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. mstsc 远程序桌面登录的 c#开发

    public AxMSTSCLib.AxMsRdpClient rdpClient; rdpClient = new AxMSTSCLib.AxMsRdpClient(); rdpClient.Doc ...

  2. UML类图详解

    下面是类图的实例: (注:飞翔接口那里应为空心三角形) UML中类图实例 接口:空心圆+直线(唐老鸭类实现了‘讲人话’):依赖:虚线+箭头(动物和空气的关系):关联:实线+箭头(企鹅需要知道气候才迁移 ...

  3. Android基础总结(一)

    Android项目的目录结构 Activity:应用被打开时显示的界面 src:项目代码 R.java:项目中所有资源文件的资源id Android.jar:Android的jar包,导入此包方可使用 ...

  4. bzoj 2527: [Poi2011]Meteors 整体二分

    给每个国家建一个链表,这样分治过程中的复杂度就和序列长度线形相关了,无脑套整体二分就可以. (最坑的地方是如果所有位置都是一个国家,那么它的样本个数会爆longlong!!被这个坑了一次,大于p[i] ...

  5. BZOJ 2179: FFT快速傅立叶

    2179: FFT快速傅立叶 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2923  Solved: 1498[Submit][Status][Di ...

  6. 用PHPstorm同步服务器文件断开连接

    使用同步功能,PHPstorm好像会一个一个去对比服务器上的文件,导致频繁请求建立连接,服务器本地安全策略做了屏蔽,所以进入黑名单后就无法连接了

  7. MySQL 常用函数和语句笔记

    CONCAT()函数 CONCAT()函数代表着字符串的链接,例子有 SELECT COUNT(1) FROM ums_commodity WHERE 1 = 1 and deleted=0 and ...

  8. php桥接设计模式

    <?php //桥接模式 abstract class info{ protected $send=null; public function __construct($send){ $this ...

  9. 迭代器学习之一:使用IEnumerable和IEnumerator接口

    写博客是检验我学习的成果之一以及自我总结的一种方式,以后会经常利用这种方式进行技术交流和自我总结,其中认识不深难免会有错误,但是一直懂得不懂就问,不懂就学的道理! 1.首先看一个简单的列子 , , , ...

  10. Google 地图 API V3 使用入门

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...