CoreAnimation--CALayer的动画

核心动画中所有类都遵守CAMediaTiming

CAAnaimation和CAPropertyAnimation都是抽象类,本身不具备动画效果,必须用它的子类才有动画效果。

CAAnimationGroup是个动画组,可以同时进行缩放,旋转。

CABasicAnimation基本动画,做一些简单效果。

CAKeyframeAnimation帧动画,做一些连续的流畅的动画。

CATransition是转场动画,界面之间跳转都可以用转场动画。

ios layer 动画-(transform.scale篇)

x轴缩放:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:1];
theAnimation.toValue = [NSNumber numberWithFloat:0.5];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

y轴缩放:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:1];
theAnimation.toValue = [NSNumber numberWithFloat:0.5];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

x轴,y轴同时按比例缩放:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:1];
theAnimation.toValue = [NSNumber numberWithFloat:0.5];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

以上缩放是以view的中心点为中心缩放的,如果需要自定义缩放点,可以设置卯点:
//中心点
[yourView.layer setAnchorPoint:CGPointMake(0.5, 0.5)];

//左上角
[yourView.layer setAnchorPoint:CGPointMake(0, 0)];

//右下角
[yourView.layer setAnchorPoint:CGPointMake(1, 1)];

 

ios layer 动画-(transform.rotation篇)

x轴旋转:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:0];
theAnimation.toValue = [NSNumber numberWithFloat:3.1415926];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

y轴旋转:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:0];
theAnimation.toValue = [NSNumber numberWithFloat:3.1415926];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

z轴旋转:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:0];
theAnimation.toValue = [NSNumber numberWithFloat:3.1415926];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

以上缩放是以view的中心点为中心缩放的,如果需要自定义缩放点,可以设置卯点:
//中心点
[yourView.layer setAnchorPoint:CGPointMake(0.5, 0.5)];

//左上角
[yourView.layer setAnchorPoint:CGPointMake(0, 0)];

//右下角
[yourView.layer setAnchorPoint:CGPointMake(1, 1)];

可设参数:

theAnimation.repeatCount = 0;
theAnimation.autoreverses = NO;

旋转的另一种实现:(以下代码绕z轴旋转180度)
    [self.topViewController.view.layer setAnchorPoint:CGPointMake(0.5, 0.5)];
    [self.topViewController.view.layer setTransform:CATransform3DMakeRotation(0, 0, 0, 1)];
    [UIView animateWithDuration:8 delay:0.0f options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseIn animations:^{
        [self.topViewController.view.layer setTransform:CATransform3DMakeRotation(3.1415926, 0, 0, 1)];
    } completion:^(BOOL finished) {
    }];

 

CATransition 过渡动画

CATransition *animation = [CATransition animation];

animation.duration = 0.3;

animation.type = @"cube";  //转场动画type见后文

animation.subtype = kCATransitionFromLeft;

[[self.tableView layer] addAnimation:animation forKey:@"myAnimation"];

  animation.fillMode = kCAFillModeBackwards;
  animation.startProgress = 0.01;
  animation.endProgress = 0.99;
使用过渡动画,实现在同一个view上,左推,右推等各种动画,节省一个view;

参数说明:

setType:可以返回四种类型:

  kCATransitionFade淡出

  kCATransitionMoveIn覆盖原图

  kCATransitionPush推出

  kCATransitionReveal底部显出来

setSubtype:也可以有四种类型:

  kCATransitionFromRight;

  kCATransitionFromLeft(默认值)

  kCATransitionFromTop;

  kCATransitionFromBottom

[animation setType:@"type类型"]; 可用的type类型主要有:

  pageCurl 向上翻一页

  pageUnCurl 向下翻一页

  rippleEffect 滴水效果

  suckEffect 收缩效果,如一块布被抽走

  cube 立方体效果

  oglFlip 上下翻转效果

/** 转场动画type一览表 **/

fade 交叉淡化过渡

push 新视图把旧视图推出去

moveIn 新视图移到旧视图上面

reveal 将旧视图移开,显示下面的新视图

cube 立方体翻滚效果

oglFlip 上下左右翻转效果

suckEffect 收缩效果,如一块布被抽走

rippleEffect 水滴效果

pageCurl  向上翻页效果

pageUnCurl  向下翻页效果

cameraIrisHollowOpen 相机镜头打开效果

cameraIrisHollowClose 相机镜头关闭效果

转自:http://blog.163.com/it__man/blog/static/137199904201301722556447/

CoreAnimation--CALayer的动画的更多相关文章

  1. CoreAnimation (CALayer 动画)

    CoreAnimation基本介绍: CoreAnimation动画位于iOS框架的Media层 CoreAnimation动画实现需要添加QuartzCore.Framework CoreAnima ...

  2. iOS 用CALayer实现动画

    与动画有关的几个类的继承关系 涉及到动画的类主要有6个,看一下它们的基本用途: 1. CAAnimation  动画基类 2. CAAnimationGroup 组合多个动画 3. CAPropert ...

  3. CALayer帧动画

    CALayer帧动画 _sunLayer = [[CALayer alloc]init]; _sunLayer.contents = (id)[UIImage imageNamed:@"su ...

  4. Quartz2D复习(四) --- 图层CALayer和动画CAAnimation

    1.CALayer 1).在ios中,能看得见摸得着的东西基本上都是UIView, 比如按钮.文本标签.文本输入框.图标等,这些都是UIView 2).UIView之所以能显示在屏幕上,完全是因为它内 ...

  5. CoreAnimation —— CALayer

    概述 如上篇博文讲述,UIView中封装了很多系统方法,可以满足我们的大部分需求.但是,其也有很多限制.那些方法产生的动画基本单元为UIView,是非常重量级的对象,而且也不支持三维布局,大部分是对视 ...

  6. [iOS Animation]-CALayer 定时器动画

    定时器的动画 我可以指导你,但是你必须按照我说的做. -- 骇客帝国 在第10章“缓冲”中,我们研究了CAMediaTimingFunction,它是一个通过控制动画缓冲来模拟物理效果例如加速或者减速 ...

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

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

  8. CoreAnimation中layer动画闪烁的原因及解决

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 网上有一段Core Animation层动画的例子,是将vie ...

  9. iOS:CALayer核心动画层

    CALayer:核心动画层 简介: Core Animation 是跨平台的,支持iOS环境和Mac OS X环境 学习核心动画之前,需要先理解CALayer,因为核心动画操作的对象不是UIView, ...

  10. iOS:CALayer核心动画层上绘图

    在CALayer上绘图: •要在CALayer上绘图,有两种方法: 1.创建一个CALayer的子类,然后覆盖drawInContext:方法,可以使用Quartz2D API在其中进行绘图 2.设置 ...

随机推荐

  1. 网易大手笔领投美国VR触觉公司AxonVR

    12月8日消息,美国西雅图VR触觉公司AxonVR今日宣布完成了580万美元的种子轮融资,由中国网易和Dawn Patrol Ventures领投.此次融资完成后AxonVR的总融资额将攀升至700万 ...

  2. BZOJ2190 & 欧拉函数

    题意: 求1-n内互质数对个数 SOL: 裸欧拉函数,还有莫比乌斯反演的加速什么的,挖个坑. Code: /*============================================= ...

  3. odeforces Beta Round #77 (Div. 2 Only)

    A. Football time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  4. 使用TCMalloc优化OpenResty

    1.安装依赖包 yum -y install wget gcc gcc-c++ -y 2.安装libunwind库可以从http://ftp.twaren.net/Unix/NonGNU//libun ...

  5. Sphinx 配置文件的说明【备忘】

    ## 数据源src1 source src1 { ## 说明数据源的类型.数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python ## 有人会奇怪,python ...

  6. Leetcode Word Break

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

  7. Codeforces Round #246 (Div. 2) A. Choosing Teams

    给定n k以及n个人已参加的比赛数,让你判断最少还能参加k次比赛的队伍数,每对3人,每个人最多参加5次比赛 #include <iostream> using namespace std; ...

  8. JavaScript进阶(二)

    什么是事件 JavaScript 创建动态页面.事件是可以被 JavaScript 侦测到的行为. 网页中的每个元素都可以产生某些可以触发 JavaScript 函数或程序的事件. 比如说,当用户单击 ...

  9. 【Eclipse】几个最重要的快捷键

    1几个最重要的快捷键    代码助手:Ctrl+Space(简体中文操作系统是Alt+/) 快速修正:Ctrl+1 单词补全:Alt+/ 打开外部Java文档:Shift+F2   显示搜索对话框:C ...

  10. 关于VSS上的项目源码管理的注意问题

    1.将项目添加到vss上面去 如果项目取的名字没有问题,则不需要去vss上面去新建项目,直接在解决方案那里右击“添加到vss”中,把第一个输入框中的名字(xxxx.root)全部清除掉.确定即可. 2 ...