在阅读本文之前,可以看看 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例子(简单动画实现)的更多相关文章

  1. [iOS Animation]-CALayer 隐式动画

    隐式动画 按照我的意思去做,而不是我说的. -- 埃德娜,辛普森 我们在第一部分讨论了Core Animation除了动画之外可以做到的任何事情.但是动画是Core Animation库一个非常显著的 ...

  2. iOS Animation 主流炫酷动画框架(特效)收集整理 #91

    https://github.com/sxyx2008/DevArticles/issues/91

  3. IOS Animation-CABasicAnimation例子(简单动画实现)

    这些例子都是CABasicAnimation的一些简单实现的动画,例如移动.透明度.翻转等等.方法里面传入一个CALayer类或者子类就可以了. 下面是用swift实现的,这些方法我们也可以用作公共类 ...

  4. [iOS Animation]-CALayer 显示动画

    显式动画 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念.隐式动画是在iOS平台创建动态用户界面的一种直接方式,也是UIKit动画机制的基础,不过它并不能涵盖所有的动 ...

  5. iOS CAReplicatorLayer 简单动画

    代码地址如下:http://www.demodashi.com/demo/11601.html 写在最前面,最近在看学习的时候,偶然间发现一个没有用过的Layer,于是抽空研究了下,本来应该能提前记录 ...

  6. Swift 实现iOS Animation动画教程

    这是一篇翻译文章.原文出处:http://www.raywenderlich.com/95910/uiview-animation-swift-tutorial 动画( animation)是iOS用 ...

  7. iOS Core Animation学习总结(3)--动画的基本类型

    一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...

  8. ios animation 动画效果实现

    1.过渡动画 CATransition CATransition *animation = [CATransition animation]; [animation setDuration:1.0]; ...

  9. iOS简单动画效果:闪烁、移动、旋转、路径、组合

    #define kDegreesToRadian(x) (M_PI * (x) / 180.0) #define kRadianToDegrees(radian) (radian*180.0)/(M_ ...

随机推荐

  1. eclipse生成uml

    安装eclipse插件在help->Install new software里面add 有本地和网络两种 1.ModelGoon 该插件需要在file中new ModelGoon Diagram ...

  2. python __call__内置函数

    __call__实现可以直接调用对象的作用

  3. DUT Star Round2

    A.Zeratu的军训游戏 Problems: 开灯问题,问无数次操作之后第n盏灯的状态 Analysis: cj:平方数有奇数个约数 Tags: Implementation B.Zeratud的完 ...

  4. QQ在线客服JS代码,自适应漂浮在网页右侧

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  5. 13.Xcode开发的快捷键

    1.文件 CMD + N: 新文件: CMD + SHIFT + N: 新项目: CMD + O: 打开: CMD + S: 保存: CMD + SHIFT + S: 另存为: CMD + W: 关闭 ...

  6. VS2013无调试信息

    Debug模式,运行时完全正常,但是一调试就出现对话框,显示出错信息: "无法找到"XXX.exe"的调试信息,或者调试信息不匹配.未使用调试信息生成二进制文件.&quo ...

  7. hdu 5795

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. Spring 学习笔记 7. 尚硅谷_佟刚_Spring_Bean 的作用域

    1,理论 •在 Spring 中, 可以在 <bean> 元素的 scope 属性里设置 Bean 的作用域. •默认情况下, Spring 只为每个在 IOC 容器里声明的 Bean 创 ...

  9. shell 条件判断语句整理

    常用系统变量 1)         $0 当前程式的名称 2)         $n 当前程式的第n个参数,n=1,2,…9 3)         $* 当前程式的任何参数(不包括程式本身) 4)   ...

  10. Unity中使用多构造函数(转)

    如果要实例化的类只有一个构造函数, 则使用方法很简单使用方法如下: 1 2 3 4 5 6 7 using (IUnityContainer container = new UnityContaine ...