图层的一些基本动画效果

#define kRadianToDegrees (radian) (radian * 180.0) / (M_PI)

  • //闪烁

[self.testView.layer addAnimation:[self opacityForever_Animation:0.5] forKey:nil];

  • //移动

[self.testView.layer addAnimation:[self duration:3 move:[NSNumber numberWithInteger:200]] forKey:nil];

  • //缩放

[self.testView.layer addAnimation:[self scale:[NSNumber numberWithInteger:1] orgin:[NSNumber numberWithInteger:3] durTimes:1 Rep:MAXFLOAT] forKey:nil] ;

  • //组合

NSArray *myArray = [NSArray arrayWithObjects:[self opacityForever_Animation:0.5], [self duration:1.0f move:[NSNumber numberWithFloat:200.0f]], [self scale:[NSNumber numberWithFloat:1.0f] orgin:[NSNumber numberWithFloat:3.0f] durTimes:2.0f Rep:MAXFLOAT], nil];

[self.testView.layer addAnimation:[self groupAnimation:myArray durTimes:3.0f Rep:MAXFLOAT] forKey:nil];

  • //路径

CGMutablePathRef myPah = CGPathCreateMutable();

CGPathMoveToPoint(myPah, nil,30, 77);

CGPathAddCurveToPoint(myPah, nil, 50, 50, 60, 200, 200, 200);//这里的是控制点。

[self.testView.layer addAnimation:[self keyframeAnimation:myPah durTimes:5 Rep:MAXFLOAT] forKey:nil];

  • //旋转

[self.testView.layer addAnimation:[self rotation:2 degree:kRadianToDegrees(90) direction:1 repeatCount:MAXFLOAT] forKey:nil];

  • //移除

[self.testView.layer removeAllAnimations];

/********************************方法的实现**************************************/

  • #pragma mark === 闪烁 ======
 - (CABasicAnimation *)opacityForever_Animation:(float)time

 {

 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];//必须写opacity才行。

 animation.fromValue = [NSNumber numberWithFloat:1.0f];

 animation.toValue = [NSNumber numberWithFloat:0.0f];//这是透明度。

 animation.autoreverses = YES;

 animation.duration = time;

 animation.repeatCount = MAXFLOAT;

 animation.removedOnCompletion = NO;

 animation.fillMode = kCAFillModeForwards;

 animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];///没有的话是均匀的动画。

 return animation;

 }
  • #pragma mark =====横向、纵向移动===========
 -(CABasicAnimation *)duration:(float)time move:(NSNumber *)x

 {

 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///.y的话就向下移动。

 animation.toValue = x;

 animation.duration = time;

 animation.removedOnCompletion = NO;//yes的话,又返回原位置了。

 animation.repeatCount = MAXFLOAT;

 animation.fillMode = kCAFillModeForwards;

 return animation;

 }
  • #pragma mark =====缩放-=============
 -(CABasicAnimation *)scale:(NSNumber *)Multiple orgin:(NSNumber *)orginMultiple durTimes:(float)time Rep:(float)repertTimes

 {

 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

 animation.fromValue = Multiple;

 animation.toValue = orginMultiple;

 animation.autoreverses = YES;

 animation.repeatCount = repertTimes;

 animation.duration = time;//不设置时候的话,有一个默认的缩放时间.

 animation.removedOnCompletion = NO;

 animation.fillMode = kCAFillModeForwards;

 return  animation;

 }
  • #pragma mark =====组合动画-=============
 -(CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes

 {

 CAAnimationGroup *animation = [CAAnimationGroup animation];

 animation.animations = animationAry;

 animation.duration = time;

 animation.removedOnCompletion = NO;

 animation.repeatCount = repeatTimes;

 animation.fillMode = kCAFillModeForwards;

 return animation;

 }
  • #pragma mark =====路径动画-=============
 -(CAKeyframeAnimation *)keyframeAnimation:(CGMutablePathRef)path durTimes:(float)time Rep:(float)repeatTimes

 {

 CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

 animation.path = path;

 animation.removedOnCompletion = NO;

 animation.fillMode = kCAFillModeForwards;

 animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

 animation.autoreverses = NO;

 animation.duration = time;

 animation.repeatCount = repeatTimes;

 return animation;

 }

 #pragma mark ====旋转动画======
 -(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount

 {

 CATransform3D rotationTransform = CATransform3DMakeRotation(degree, , , direction);

 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];

 animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];

 animation.duration  =  dur;

 animation.autoreverses = NO;

 animation.cumulative = NO;

 animation.fillMode = kCAFillModeForwards;

 animation.repeatCount = repeatCount;

 animation.delegate = self;

 return animation;

 }

iOS开发——图形与动画篇OC篇&图层基本上动画的更多相关文章

  1. iOS开发——图形编程OC篇&粘性动画以及果冻效果

    粘性动画以及果冻效果 在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: 先做个提纲 ...

  2. iOS开发——图形编程Swift篇&CAShapeLayer实现圆形图片加载动画

    CAShapeLayer实现圆形图片加载动画 几个星期之前,Michael Villar在Motion试验中创建一个非常有趣的加载动画. 下面的GIF图片展示这个加载动画,它将一个圆形进度指示器和圆形 ...

  3. iOS开发——UI篇OC篇&SpriteKit详解

    SpriteKit详解 SpriteKit,iOS/Mac游戏制作的新纪元 这是我的WWDC2013系列笔记中的一篇,完整的笔记列表请参看这篇总览.本文仅作为个人记录使用,也欢迎在许可协议范围内转载或 ...

  4. iOS开发——UI篇OC篇&UIDynamic详解

    iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟 ...

  5. iOS开发——UI篇OC篇&UITableView简单封装

    UITableView简单封装 UITableView时iOS开发中使用最多也是最重的一个UI空间,其实在App Store里面的%80以上的应用都用到了这个控件,所以就给大家介绍一下,前面的文章中也 ...

  6. iOS开发——UI篇OC篇&UIStackView详解

    UIStackView详解 一.继承关系.遵守协议.隶属框架及可用平台 UIStackView 类提供了一个高效的接口用于平铺一行或一列的视图组合.Stack视图使你依靠自动布局的能力,创建用户接口使 ...

  7. iOS开发——UI篇OC篇&TextField作为搜索框的使用

    TextField作为搜索框的使用 在iOS开发中我们经常会使用到搜索框,但是有的时候系统自带的搜索框不足以满足我吗想要的功能,这个时候我们就可以使用自定义的搜索框实现想要的功能. 今天就简单的介绍一 ...

  8. iOS开发:深入理解GCD 第一篇

    最近把其他书籍都放下了,主要是在研究GCD.如果是为了工作,以我以前所学的GCD.NSOperation等知识已经足够用了,但学习并不仅仅知识满足于用它,要知其然.并且知其所以然,这样才可以不断的提高 ...

  9. iOS开发 - 多线程实现方案之Pthread篇

    pthread基础 pthread是POSIX thread的简写,一套通用的多线程API,适用于Unix.Linux.Windows等系统,跨平台.可移植,使用难度大,C语言框架,线程生命周期由程序 ...

  10. iOS开发:深入理解GCD 第二篇(dispatch_group、dispatch_barrier、基于线程安全的多读单写)

    Dispatch Group在追加到Dispatch Queue中的多个任务处理完毕之后想执行结束处理,这种需求会经常出现.如果只是使用一个Serial Dispatch Queue(串行队列)时,只 ...

随机推荐

  1. longest common str

    #include <vector> #include <iostream> #include <string> using namespace std; int l ...

  2. HDU 1025-Constructing Roads In JGShining's Kingdom(最长不降子序列,线段树优化)

    分析: 最长不降子序列,n很大o(n^2)肯定超,想到了小明序列那个题用线段树维护前面的最大值即可 该题也可用二分搜索来做. 注意问题输出时的坑,路复数后加s #include <map> ...

  3. 关于C++ vector的拷贝

    定义了vector变量,在使用时直接用了等号赋值,后来发现有问题,就查了一下vector怎么赋值? 说明:vector是一个构造对象,不能直接使用=符号进行复制,必须迭代每个元素来复制.或者重载=操作 ...

  4. NodeJS:树的反序列化

    !!不知问啥,cnblog的MarkDown编辑器不好使了. 本文也在我的博客edwardesire.com上,欢迎品尝. 树的反序列化就是将序列数组安装线索组成树结构,今次项目数据库存储决策节点的方 ...

  5. ES6学习小计

    1.增加了for of语法,对应C#里的foreach,注意ES5中的 for in只会传递0,1,2.....序号,并且是字符for-of循环语句通过方法调用来遍历各种集合.数组.Maps对象.Se ...

  6. RTMP、RTSP、HTTP视频协议详解(转)

    一.RTMP.RTSP.HTTP协议 这三个协议都属于互联网 TCP/IP 五层体系结构中应用层的协议.理论上这三种都可以用来做视频直播或点播.但通常来说,直播一般用 RTMP.RTSP.而点播用 H ...

  7. UVA 315 315 - Network(求割点个数)

     Network  A Telephone Line Company (TLC) is establishing a new telephone cable network. They are con ...

  8. CentOS查看系统信息-CentOS查看命令

    一:查看cpu more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo 如 ...

  9. javascript 获取HTML DOM父、子、临近节点

    在Web应用程序特别是Web2.0程序开发中,经常要获取页面中某个元素,然后更新该元素的样式.内容等.如何获取要更新的元素,是首先要解决的问题.令人欣慰的是,使用JavaScript获取节点的方法有很 ...

  10. UVa 817 According to Bartjens (暴力,DFS)

    题意:给出一个数字组成的字符串,然后在字符串内添加三种运算符号 * + - ,要求输出所有添加运算符并运算后结果等于2000的式子. 所有数字不能有前导0, 且式子必须是合法的. 析:这个题很明显的暴 ...