Swift - 使用CAKeyframeAnimation实现关键帧动画
1,CAKeyframeAnimation介绍
|
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 = selfoverride func animationDidStart(anim: CAAnimation!) { println("动画开始")}override func animationDidStop(anim: CAAnimation!, finished flag: Bool) { println("动画结束")} |
PS:苹果官网API - CAKeyframeAnimation
Swift - 使用CAKeyframeAnimation实现关键帧动画的更多相关文章
- 核心动画基础动画(CABasicAnimation)关键帧动画
1.在iOS中核心动画分为几类: 基础动画(CABasicAnimation) 关键帧动画(CAKeyframeAnimation) 动画组(CAAnimationGroup) 转场动画(CATran ...
- IOS开发-属性动画和关键帧动画的使用
CAMediaTiming是一个协议(protocol),CAAnimation是所有动画类的父类,但是它不能直接使用,应该使用它的子类. 继承关系: CoreAnmiation 核心动画 简写CA ...
- Core Animation 动画的使用:关键帧动画、基础动画、动画组
首先让我们了解下什么是 Core Animation,Core Animation 为核心动画,他为图形渲染和动画提供了基础.使用核心动画,我们只需要设置起点.终点.关键帧等一些参数,剩下的工作核心动 ...
- ios基础动画、关键帧动画、动画组、转场动画等
概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互式绘图,如何通过核心动画创建基础动画.关键帧动画 ...
- iOS:核心动画之关键帧动画CAKeyframeAnimation
CAKeyframeAnimation——关键帧动画 关键帧动画,也是CAPropertyAnimation的子类,与CABasicAnimation的区别是: –CABasicAnimation只能 ...
- core Animation之CAKeyframeAnimation(关键帧动画)
CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSA ...
- IOS第18天(6,CAKeyframeAnimation关键帧动画)
******* #import "HMViewController.h" @interface HMViewController () @property (weak, nonat ...
- [Xcode 实际操作]九、实用进阶-(20)创建位移关键帧动画:通过添加运动关键点制作位移动画
目录:[Swift]Xcode实际操作 本文将演示如何通过添加运动关键点的方式,来制作位移动画 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIK ...
- iOS开发UI篇—核心动画(关键帧动画)
转自:http://www.cnblogs.com/wendingding/p/3801330.html iOS开发UI篇—核心动画(关键帧动画) 一.简单介绍 是CApropertyAnimatio ...
随机推荐
- 软件工程(FZU2015)助教总结
本次构建之法-SE助教工作,和福州大学张老师协作,福大学生基本发挥出了一定水平,在此做个小结. 教师 张老师本身的SE教学经验足够丰富,对教学工作中的教师.助教.学生的角色定位清晰,整体节奏和安排合理 ...
- 1201MySQL配置文件mysql.ini参数详解
转自http://www.cnblogs.com/feichexia/archive/2012/11/27/mysqlconf.html my.ini(Linux系统下是my.cnf),当mysql服 ...
- Sunny-ngrok 解决外网访问内网问题
该博文已过时 请参考官网 http://www.ngrok.cc/ 一 .进入 网址 往下拉找到: 下载不同的版本. 二. 平台登陆地址:http://www.ngrok. ...
- [CG编程] 基本光照模型的实现与拓展以及常见光照模型解析
0.前言 这篇文章写于去年的暑假.大二的假期时间多,小组便开发一个手机游戏的项目,开发过程中忙里偷闲地了解了Unity的shader编写,而CG又与shaderLab相似,所以又阅读了<CG教程 ...
- qthread 使用 signal 方法通信
因为之间尝试过的 signal 机制,都是在 emit singnal_my() 的地方,直接调用了 slot 函数:相当于,slot 只是一个回调函数. 所以,在这里有点困惑,如果是要顺序执行完 s ...
- 狼人杀BETA阶段计划简介
狼人杀beta阶段任务与目标 简介 一.前言 狼人杀alpha阶段终于在组团刷夜中结束了,我们取得了一些成绩,同时也暴露了团队的一些问题.但不管怎样,有了在alpha版本中收获的经验,我们将在beta ...
- 【Phylab2.0】Alpha版本项目展示
团队成员 冯炜韬(PM)http://www.cnblogs.com/toka 岳桐宇(后端)http://www.cnblogs.com/mycraftmw 杨子琛(测试&LaTeX)htt ...
- js只弹窗一次
<script> var alertmessage="检测到您当前浏览器为IE8或以下版本,建议您使用IE9或以上版本,或者火狐.谷歌浏览器,才能体验到最佳效果" fu ...
- .Net创建windows服务入门
本文主要记录学习.net 如何创建windows服务. 1.创建一个Windows服务程序 2.新建安装程序 3.修改service文件 代码如下 protected override void On ...
- 2015.4.24 移动端,chrome不兼容或无法运行的一些具体问题
1.table内input,把它的边框和focus边框都变成透明,在ff可行,但是chrome会有样式,怎么解决? 解决方法:border:none;outline:0; 2.如下代码,css3动画在 ...