图层的一些基本动画效果

#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. HDU 2056 Rectangles

    Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. [Everyday Mathematics]20150128

    求极限 $$\bex \lim_{x\to 0}\sex{\frac{e^x+e^{2x}+\cdots+e^{nx}}{n}}^\frac{1}{x}. \eex$$

  3. 位图引起的内存溢出OutOfMemory解决方案

    一.问题描述:Android下的相机在独自使用时,拍照没有问题,通过我们的代码调用时,也正常,但是更换了不同厂商的平板,ROM由Android4.0变成了Android4.1后,拍照出现了OutOfM ...

  4. 机器学习真的可以起作用吗?(2)(以二维PLA算法为例)

    一个问题:大多数情况下,M(hypothesis set的大小)是无穷大的,例如PLA算法.那么是不是我们的原则1就不能使用了? 我们试着做一些努力: Step1:寻找hypothesis set的e ...

  5. 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point

    // 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point // 思路:直接暴力绝对T // 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点.枚举x的范围,再 ...

  6. 制作java可执行程序的方法

    命令行方法: 1. 创建Manifest.txt文件,内容: Main-Class: com.mkyong.awt.AwtExample 2.打包所有的class,包括Manifest.txt文件: ...

  7. .NET Reactor 命令行使用

    安装.NET Reactor工具软件.例如你的安装目录为:D:\Program Files\Eziriz\.NET Reactor 按如下步骤设置系统环境变量path. 将path变量的值中加入.NE ...

  8. Xamarin.Android真机调试时闪退解决办法

    项目->属性->Android Options,Packaging页签 去掉 Use Shared Runtime可解决

  9. 问题-Delphi2007跟踪变量时提示“E2171 Variable 'APolygon' inaccessible here due to optimization”

    问题现象:Delphi2007跟踪变量时提示“E2171 Variable 'APolygon' inaccessible here due to optimization” . 问题原因:可能是因为 ...

  10. C#简单应用spring的例子

    接口定义 namespace SpringDemo { interface IOper { void Say(); } } 此接口的两个实现 实现1 using System; namespace S ...