图层的一些基本动画效果

#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. [Papers]NSE, $u_3$, Lebesgue space [NNP, QM, 2002; Zhou, JMPA, 2005]

    $$\bex u_3\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=\frac{1}{2},\quad 6< q\leq \inft ...

  2. HDU 4035Maze(树状+概率dp,绝对经典)

    题意: 给你n个节点的树,从1节点开始走,到每个节点都有三种情况,被杀死回到1节点,找到隐藏的出口出去,沿着当前节点相邻的边走到下一个节点,给出每个节点三种情况发生的概率分别为ki,ei,1-ki-e ...

  3. codeforces 687C - The Values You Can Make 简单dp

    题意:一个数组a[i],你可以挑出若干个数(只能挑一次)加起来等于k, 针对每一种方案,你可以选出这若干个数的子集来组合新数 最后所有的方案能组合出多少种数 分析:一看数据范围n,k<=500 ...

  4. EF6 Database First (DbContext) - Change Schema at runtime

    Problem:There are two SQL databases (dev and live) with on Azure which has identical table structure ...

  5. 标准Web系统的架构分层[转]

    标准Web系统的架构分层 – 转载请注明出处 1.架构体系分层图 在上图中我们描述了Web系统架构中的组成部分.并且给出了每一层常用的技术组件/服务实现.需要注意以下几点: 系统架构是灵活的,根据需求 ...

  6. Tableau学习笔记之二

    2张图片解析下Tableau 9.0界面的功能 1.数据加载界面: 2.数据分析界面:

  7. Python 笔记 : 类和继承

    # -*- coding=  utf-8 -*- # 文件编码定义的语法规则是: coding[:=]/s*([-/w.]+) # 未指定编码将默认为 : ASCII # 同时要注意物理文件的编码也要 ...

  8. 写i2c_client驱动的两种方式

    http://www.cnblogs.com/simonshi/archive/2011/02/24/1963426.html

  9. 机器学习----分布问题(二元,多元变量分布,Beta,Dir)

    这涉及到数学的概率问题. 二元变量分布:          伯努利分布,就是0-1分布(比如一次抛硬币,正面朝上概率) 那么一次抛硬币的概率分布如下: 假设训练数据如下: 那么根据最大似然估计(MLE ...

  10. 在Windows Server 下安装 Oracle 11G 的一般步骤