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. eclipse svn proxy

    C:\Users\userName\AppData\Roaming\Subversion下的servers文件, 将#http-proxy-host和#http-proxy-port这两行前面的#号去 ...

  2. 通过Spring Mail Api发送邮件

    使用Java Mail API来发送邮件也很容易实现,但是最近公司一个同事封装的邮件API实在让我无法接受,于是便打算改用Spring Mail API来发送邮件,顺便记录下这篇文章. [Spring ...

  3. 定位absolute使内联支持宽高(块属性变为内联,内容默认撑开)margin auto 失效

    relative   没脱离文档流 absdute 完全脱离文档流 margin :auto 失效 相对整个文档偏离 相对父级定位 fixed 脱离文档流 与绝对定位特性一致 3.P标快不能包块级标签 ...

  4. [Leetcode] Word BreakII

    Question: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence w ...

  5. 【BZOJ】3456: 城市规划

    http://www.lydsy.com/JudgeOnline/problem.php?id=3456 题意:求n个点的无向连通图的方案.(n<=130000) #include <bi ...

  6. [BZOJ2794][Poi2012]Cloakroom

    2794: [Poi2012]Cloakroom Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 167  Solved: 119[Submit][St ...

  7. PHP IDE phpstorm 快捷键

    这篇文章主要介绍了PHP IDE phpstorm 常用快捷键,本文分别列出了mac系统和Windows系统下的phpstorm快捷键,需要的朋友可以参考下 一.mac电脑phpstorm快捷键 co ...

  8. OSG+VS2010+win7环境搭建---OsgEarth编译

    OSG+VS2010+win7环境搭建---OsgEarth编译 转:http://www.cnblogs.com/hnfxs/p/3161261.html Win7下 osg+vs2010环境搭建 ...

  9. Linux 的cp命令

    Linux 的cp命令 功能: 复制文件或目录说明: cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中.若 ...

  10. Node.js前端自动化工具:gulp

    前端自动化工具 -- gulp 使用简介 gulp是基于流的前端自动化构建工具. 之前也谈到了 grunt的用法,grunt其实就是配置+配置的形式. 而gulp呢,是基于stream流的形式,也就是 ...