CoreAnimation


1.CABasicAnimation

  1. // position
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"position"];
  2. // bounds
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
  3. // opacity
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"opacity"];
  4. // backgroundColor
    // 景色渐变一定用CGColor
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
  5. // transform.scale
    // 以下缩放是中心缩放,若需要自定义缩放点需要设置锚点: [self.firstView.layer setAnchorPoint:CGPointMake(0, 0)];
    // 一般,锚点位于图层中心{0.5,0.5},其度量是以单位方形而不是点为参照,无论图层有多大,右下角的坐标都是{1.0,1.0}
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  6. // transform.rotation
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"]; // x ,y ,z 默认是z
  7. // transform.translation
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; // x ,y ,z 默认是x
  8. // cornerRadius
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
  9. // borderWidth
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"borderWidth"];

以position为例

  1. // position
    - (void)postionAnimation {
    CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"position"];
    ba.toValue = [NSValue valueWithCGPoint:self.firstView.center];
    ba.duration = 0.8;
    ba.delegate = self;
    ba.removedOnCompletion = NO; // 动画结束后是否回到原状态,默YES.若为NO,则 fillMode 须为 kCAFillModeForwards
    ba.fillMode = kCAFillModeBackwards;
    ba.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; // 动画的时间节奏控制
    [self.secondView.layer addAnimation:ba forKey:@"position"];
    }

2.CAKeyframeAnimation

  1. - (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
  2. [self valuesAnimation];
    }
  3. - (void)valuesAnimation {
    CAKeyframeAnimation *kf = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    kf.fillMode = kCAFillModeForwards;
    kf.removedOnCompletion = NO;
    kf.duration = 3;
    kf.repeatCount = 0;
    NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(0, 120)];
    NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(190, 20)];
    NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(20, 300)];
    NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(300, 150)];
    kf.values = @[value1,value2,value3,value4];
  4. [self.firstView.layer addAnimation:kf forKey:@"valuesKeyframe"];
    }
  5. - (void)pathAnimation {
    CAKeyframeAnimation *kf = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    kf.duration = 3.0f;
    kf.removedOnCompletion = NO;
    kf.fillMode = kCAFillModeForwards;
    kf.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  6. CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddEllipseInRect(path, NULL, CGRectMake(0, 0, 370, 300));
  7. kf.path = path;
    CGPathRelease(path);
  8. [self.firstView.layer addAnimation:kf forKey:@"pathKeyframe"];
    }

3.CATransition
/***********type:动画过渡类型***********************

  1. kCATransitionFade 交叉淡化过渡
    kCATransitionMoveIn 新视图移到旧视图上面
    kCATransitionPush 新视图把旧视图推出去
    kCATransitionReveal 将旧视图移开,显示下面的新视图

  1. kCATransitionCube 立方体翻滚效果
    kCATransitionOglFlip 上下左右翻转效果
    kCATransitionSuckEffect 收缩效果,如一块布被抽走
    kCATransitionRippleEffect 水滴效果
    kCATransitionPageCurl 向上翻页效果
    kCATransitionPageUnCurl 向下翻页效果
    kCATransitionCameraIrisHollowOpen 相机镜头打开效果
    kCATransitionCameraIrisHollowClos 相机镜头关闭效果

************************************************************/

/***********subType:动画过渡方向***********************

  1. kCATransitionFromRight 从右边
    kCATransitionFromLeft 从左边
    kCATransitionFromTop 从顶部
    kCATransitionFromBottom 从底部

*************************************************************/
以cameraIrisHollowOpen为例

  1. - (void)cameraIrisHollowTransition {
    CATransition *t = [CATransition animation];
    t.type = @"cameraIrisHollowOpen";
    // t.type = @"cameraIrisHollowClos";
    t.subtype = kCATransitionFromLeft;
    t.duration = 1.5;
    self.firstView.backgroundColor = [UIColor colorWithRed:0.2 green:0.3 blue:0.6 alpha:1];
    [self.firstView.layer addAnimation:t forKey:@"pageCurlTransition"];
    }

4.CASpringAnimation 继承自CABasicAnimation

  1. /**
    * @author Jack Lee, 16-05-17 22:05:53
    *
    * @brief after iOS9.0
    */
    - (void)springAnimation {
    CASpringAnimation *spring = [CASpringAnimation animationWithKeyPath:@"bounds.size"];
    spring.mass = 10; // 质量,影响图层运动时的弹簧惯性,质量越大,弹簧拉伸和压缩的幅度越大
    spring.stiffness = 5000; // 刚度系数(劲度系数/弹性系数),刚度系数越大,形变产生的力就越大,运动越快
    spring.damping = 100; // 阻尼系数,阻止弹簧伸缩的系数,阻尼系数越大,停止越快
    spring.initialVelocity = 5; // 初始速率,动画视图的初始速度大小;速率为正数时,速度方向与运动方向一致,速率为负数时,速度方向与运动方向相反
    spring.duration = spring.settlingDuration; // 结算时间 返回弹簧动画到停止时的估算时间,根据当前的动画参数估算,通常弹簧动画的时间使用结算时间比较准确
    spring.toValue =[NSValue valueWithCGSize:self.firstView.bounds.size];
    spring.removedOnCompletion = NO;
    spring.fillMode = kCAFillModeForwards;
    [self.secondView.layer addAnimation:spring forKey:@"spring"];
    }

5.CAAnimationGroup

  1. - (void)groupAnimation {
    CABasicAnimation *p = [CABasicAnimation animationWithKeyPath:@"position"];
    p.toValue = [NSValue valueWithCGPoint:self.firstView.center];
  2. CABasicAnimation *o = [CABasicAnimation animationWithKeyPath:@"opacity"];
    o.toValue = @(0.2);
  3. CABasicAnimation *b = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
    b.toValue = [NSValue valueWithCGSize:self.firstView.bounds.size];
  4. CAAnimationGroup *g = [CAAnimationGroup animation];
    g.animations = @[p,o,b];
    g.duration = 0.8;
    g.removedOnCompletion = NO;
    g.fillMode = kCAFillModeForwards;
    g.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  5. [self.secondView.layer addAnimation:g forKey:@"groupAnimation"];
    }
 

CoreAnimation的更多相关文章

  1. iOS CoreAnimation详解(一) 有关Layer的动画

    以前由于项目需要 也写了一些动画 ,但是知识不系统,很散.这段时间趁着项目完成的空袭,来跟着大神的脚步系统的总结一下iOS中Core Animation的知识点. 原博客地址:http://blog. ...

  2. CoreAnimation 之CATextLayer

    如果你想在一个图层中显示文字,完全可以借助图层代理直接将Core Graphics写入图层的内容(这就是UILabel的精髓).如果雨果寄宿于图层的视图,直接在图层上操作,其实相当繁琐.你要为每一个显 ...

  3. 二、CoreAnimation之寄宿图详解

    在之前的图层树中我们知道,可以使用CALayer对象创建一些有背景颜色的图层,其实使用CALayer,不仅可以利用其展示背景颜色,还可以展示图片.而这些展示内容,其实就是CALayer的寄宿图.这一节 ...

  4. 一、CoreAnimation之图层树详解

    CoreAnimation :在字面意思为“核心动画”,但是如果您认为它仅仅是一个动画框架,那可能就要错过一些经典功能了.动画,只是CoreAnimation功能的一小部分,毕竟人家的源头是一个叫做L ...

  5. iOS CoreAnimation 核心动画

    一 介绍 一组非常强大的动画处理API 直接作用在CALAyer上,并非UIView(UIView动画) CoreAnimation是所有动画的父类,但是不能直接使用,应该使用其子类 属性: dura ...

  6. ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)

    Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...

  7. iOS关于CoreAnimation动画知识总结

    一:UIKit动画 在介绍CoreAnimation动画前先简单介绍一下UIKit动画,大部分简单的动画都可以使用UIKit动画实现,如果想实现更复杂的效果,则需要使用Core Animation了: ...

  8. CoreAnimation方法汇总

    使用CoreAnimation一般分为三个部分:1.创建执行动画的CALayer 2.创建动画 3.CALayer 添加Animation CoreAnimation是以锚点为基础. CoreAnim ...

  9. CoreAnimation笔记

    核心动画继承结构 CoreAnimation Core Animation是直接作用在CALayer上的(并非UIView上)非常强大的跨Mac OS X和iOS平台的动画处理API,Core Ani ...

  10. iOS开发之 动画CoreAnimation

    http://blog.treney.com/index.php/archives/CoreAnimation.html?hmsr=toutiao.io&utm_medium=toutiao. ...

随机推荐

  1. 2013 ACM区域赛长沙 K Pocket Cube hdu 4801

    题意:给了一个2*2的魔方..每步操作可以将任意一面翻转90度..现在问在N(<=7)步内.最多能翻出几面相同的. 直接打表模拟每种翻转情况 #include<cstdio> #in ...

  2. JavaScript高级程序设计44.pdf

    unload事件 与load事件对应的是unload事件,这个事件在文档被完全卸载后触发,只要用户从一个页面切换到另一个页面,就会发生unload事件,最多的情况是清除引用,避免内存泄漏 与load事 ...

  3. Bzoj 2456: mode 数论,众数

    2456: mode Time Limit: 1 Sec  Memory Limit: 1 MBSubmit: 2843  Solved: 1202[Submit][Status][Discuss] ...

  4. noip2011 公交观光

    描述 风景迷人的小城Y市,拥有n个美丽的景点.由于慕名而来的游客越来越多,Y市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第0分钟出现在1号景点,随后依次前往2.3.4……n号景 ...

  5. 一个PHP书单 -摘自网络

    # PHP <PHP程序设计>(第2版) –PHP语法和入门最好的书 <PHP5权威编程> –PHP入门后升级书 <深入PHP:面向对象.模式与实践>(第3版) – ...

  6. 【转】[慢查优化]联表查询注意谁是驱动表 & 你搞不清楚谁join谁更好时请放手让mysql自行判定

    转自:http://zhengyun-ustc.iteye.com/blog/1942797 写在前面的话: 不要求每个人一定理解 联表查询(join/left join/inner join等)时的 ...

  7. Tornado源码探寻(准备阶段)

    上一篇从一个简单的例子大致了解到Tornado框架的一个概述,同时也看清了web框架的本质. 接下来,我们从tornado程序的起始来分析其源码: 一.概述 上图是摘自朋友的博客里的内容,这张图很明确 ...

  8. 5步做好vsftpd

    系统:centos6.5 X86 1、yum -y install vsftpd 2、vim /etc/vsftpd/vsftpd.conf 可以用cat vsftpd.conf | grep -v ...

  9. 【转】Cannot change version of project facet Dynamic Web Module to 3.1 (Eclipse Maven唯一解决方案)

    If you want to use version 3.1 you need to use the following schema: http://xmlns.jcp.org/xml/ns/jav ...

  10. 修正android cocos2dx项目当点击属性时提示错误的问题

    近期在用cocos2dx 3.x版本号做android版本号的时候,出现点击project-属性-C/C++ builder的时候会提示 The currently displayed paye co ...