图层的一些基本动画效果

#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. [转] AE之分级颜色专题图渲染

    原文 AE之分级颜色专题图渲染 参考代码1 private void 分级渲染ToolStripMenuItem_Click(object sender, EventArgs e) { //值分级 I ...

  2. MySql相关及如何删除MySql服务

    又会一招–如何删除MySql服务 进入“控制面板->管理工具->服务”查看才发现,虽然MYSQL已经卸载了,但是MYSQL服务仍然残留在系统服务里.又不想改服务名,改怎么办呢. 后来上百度 ...

  3. [视频监控]用状态机图展示Layout切换关系

    监控系统通常会提供多种Layout给用户,用于满足不同需求,如:高清显示单路视频或者同时观察多路监控情况. 文中系统只提供了单路.2x2(2行2列共4路).8路(4行4列布局,从左上角算起,有个核心显 ...

  4. DbContext运行时动态附加上一个dbset

    参考 Creating DbSet Properties Dynamically C# code? 1 DbSet<MyEntity> set = context.Set<MyEnt ...

  5. C++小游戏:扑克牌21点

    21点扑克牌游戏: 程序说明:该程序是模拟21点扑克牌游戏,玩家最多可以要5张牌,但是如果牌的点数之和超过21点,则自动出局,在不超过21点的情况下,玩家与庄家比牌的大小,大者为赢家 程序片段分析: ...

  6. redo文件一

    redo log files and redo log buffer redo log files的作用的是确保数据库崩溃之后能正确的恢复数据库,恢复数据库到一,致性的状态 redo log file ...

  7. bzoj 3931 [CQOI2015]网络吞吐量(最短路,最大流)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3931 [题意] 只能通过1-n的最短路,求网络最大流 [思路] 分别以1,n为起点做最 ...

  8. 一起刷LeetCode2-Add Two Numbers

    今天看不进去论文,也学不进去新技术,于是先把题刷了,一会补别的. -----------------------------------------------------我才不是分割线------- ...

  9. 举例详细说明javascript作用域、闭包原理以及性能问题(转)

    转自:http://www.cnblogs.com/mrsunny/archive/2011/11/03/2233978.html 这可能是每一个jser都曾经为之头疼的却又非常经典的问题,关系到内存 ...

  10. Tengine – Nginx衍生版

    Tengine是淘宝在Nginx基础上开发的一个衍生版.官方的简介说针对大访问量网站的需求,添加了很多高级功能和特性.Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验. ...