IOS Animation-CAKeyframeAnimation例子(简单动画实现)
在阅读本文之前,可以看看 CABasicAnimation的例子
也可以看看IOS Animation-CABasicAnimation、CAKeyframeAnimation详解&区别&联系
1)让一个layer左右晃动
//让一个layer左右晃动
func addLayerKeyframeAnimationRock(layer:CALayer) {
let animation = CAKeyframeAnimation(keyPath: "position.x")
animation.values = [, , -, ]
//additive设置为true是使Core Animation 在更新 presentation layer 之前将动画的值添加到 model layer 中去。可以看到上面的values是0,10,-10,0. 没有设置的话values=layer.position.x+0, layer.position.x+10, layer.position.x-10
animation.additive = true
animation.duration = 0.3
animation.repeatCount = layer.addAnimation(animation, forKey: "addLayerKeyframeAnimationRock")
}
2)让一个layer圆周(圆圈)运动
//让一个layer圆周(圆圈)运动
func addLayerKeyframeAnimationOrbit(layer:CALayer) {
let animation = CAKeyframeAnimation(keyPath: "position")
let boundingRect = CGRectMake(layer.frame.origin.x, layer.frame.origin.y, , )
animation.path = CGPathCreateWithEllipseInRect(boundingRect,nil)
animation.duration =
animation.repeatCount = HUGE
//其值为kCAAnimationPaced,保证动画向被驱动的对象施加一个恒定速度,不管路径的各个线段有多长,并且无视我们已经设置的keyTimes
animation.calculationMode = kCAAnimationPaced
//kCAAnimationRotateAuto,确定其沿着路径旋转(具体要自己来体验,这里难解释)
animation.rotationMode = kCAAnimationRotateAuto layer.addAnimation(animation, forKey: "addLayerKeyframeAnimationOrbit")
}
可以关注本人的公众号,多年经验的原创文章共享给大家。

IOS Animation-CAKeyframeAnimation例子(简单动画实现)的更多相关文章
- [iOS Animation]-CALayer 隐式动画
隐式动画 按照我的意思去做,而不是我说的. -- 埃德娜,辛普森 我们在第一部分讨论了Core Animation除了动画之外可以做到的任何事情.但是动画是Core Animation库一个非常显著的 ...
- iOS Animation 主流炫酷动画框架(特效)收集整理 #91
https://github.com/sxyx2008/DevArticles/issues/91
- IOS Animation-CABasicAnimation例子(简单动画实现)
这些例子都是CABasicAnimation的一些简单实现的动画,例如移动.透明度.翻转等等.方法里面传入一个CALayer类或者子类就可以了. 下面是用swift实现的,这些方法我们也可以用作公共类 ...
- [iOS Animation]-CALayer 显示动画
显式动画 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念.隐式动画是在iOS平台创建动态用户界面的一种直接方式,也是UIKit动画机制的基础,不过它并不能涵盖所有的动 ...
- iOS CAReplicatorLayer 简单动画
代码地址如下:http://www.demodashi.com/demo/11601.html 写在最前面,最近在看学习的时候,偶然间发现一个没有用过的Layer,于是抽空研究了下,本来应该能提前记录 ...
- Swift 实现iOS Animation动画教程
这是一篇翻译文章.原文出处:http://www.raywenderlich.com/95910/uiview-animation-swift-tutorial 动画( animation)是iOS用 ...
- iOS Core Animation学习总结(3)--动画的基本类型
一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...
- ios animation 动画效果实现
1.过渡动画 CATransition CATransition *animation = [CATransition animation]; [animation setDuration:1.0]; ...
- iOS简单动画效果:闪烁、移动、旋转、路径、组合
#define kDegreesToRadian(x) (M_PI * (x) / 180.0) #define kRadianToDegrees(radian) (radian*180.0)/(M_ ...
随机推荐
- 本地socket使用AF_UNIX
int socket(int domain, int type, int protocol); domain参数代表地址族,我们最常用的是TCP/IP协议通信中使用的是AF_INET,在有些情况下建立 ...
- HDU 1575
Tr A Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 怎么实现CSS限制字数,超出部份显示点点点.
如何实现CSS限制字数,超出部份显示点点点... <div style="width:200px; white-space:nowrap;overflow:hidden;text-ov ...
- Mini projects #6 ---- Blackjack
课程全名:An Introduction to Interactive Programming in Python,来自 Rice University 授课教授:Joe Warren, Scott ...
- ruby日记1
1.irb参数配置 ~/.irbrc IRB.conf[:PROMPT_MODE] = :SIMPLE #简化 irb 提示符,以及禁用一些烦人的自动缩进行为 IRB.conf[:AUTO_INDEN ...
- 用js实现瀑布流的一种简单方法
现在说瀑布流式布局似乎有点晚了,但是每一项技术都是向着“精”和“简”的方向在不断发展,在发展到极致之前,需要一个相当漫长的过程,因此,从这个角度来说,当瀑布流被应用得越来越多的时候,反而更应该讨论它, ...
- 《LINUX内核设计与实现》读书笔记之第五章
第五章——系统调用 5.1 与内核通信 1.为用户空间提供一种硬件的抽象接口 2.保证系统稳定和安全 3.除异常和陷入,是内核唯一的合法入口. API.POSIX和C库 关于Unix接口设计:提供机制 ...
- Execution Order of Event Functions
In Unity scripting, there are a number of event functions that get executed in a predetermined order ...
- Struts2中获取servlet API的几种方式
struts2是一个全新的MVC框架,如今被广大的企业和开发者所使用,它的功能非常强大.这给我们在使用servlet 纯java代码写项目的时候带来了福音.但是一般来说,我们的项目不到一定规模并不需要 ...
- oracle数据库常用查询
一.数据库信息 1.数据库时间 select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') AS dbtime from dual; 2.主机OS类型 SELEC ...