#define kDegreesToRadian(x) (M_PI * (x) / 180.0)

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

- (void)viewDidLoad

{

[superviewDidLoad];

self.title = @"测试动画";

self.view.backgroundColor = [UIColor lightGrayColor];

myTest1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 60, 40)];

myTest1.backgroundColor = [UIColor blueColor];

myTest1.textAlignment = NSTextAlignmentCenter;

myTest1.text = @"张明炜";

myTest1.textColor = [UIColor whiteColor];

[self.view addSubview:myTest1];

//闪烁效果。

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

///移动的动画。

//    [myTest1.layer addAnimation:[self moveX:1.0f X:[NSNumber numberWithFloat:200.0f]] forKey:nil];

//缩放效果。

//    [myTest1.layer addAnimation:[self scale:[NSNumber numberWithFloat:1.0f] orgin:[NSNumber numberWithFloat:3.0f] durTimes:2.0f Rep:MAXFLOAT] forKey:nil];

//组合动画。

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

//    [myTest1.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);//这里的是控制点。

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

//旋转动画。

[myTest1.layeraddAnimation:[self rotation:2 degree:kRadianToDegrees(90) direction:1 repeatCount:MAXFLOAT] forKey:nil];

}

#pragma mark === 永久闪烁的动画 ======

-(CABasicACnimation *)opacityForever_Animation:(float)time

{

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

animation.fromValue = [NSNumbernumberWithFloat:1.0f];

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

animation.autoreverses = YES;

animation.duration = time;

animation.repeatCount = MAXFLOAT;

animation.removedOnCompletion = NO;

animation.fillMode = kCAFillModeForwards;

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

return animation;

}

#pragma mark =====横向、纵向移动===========

-(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x

{

CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"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 = [CABasicAnimationanimationWithKeyPath:@"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 = [CAAnimationGroupanimation];

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 = [CAKeyframeAnimationanimationWithKeyPath:@"position"];

animation.path = path;

animation.removedOnCompletion = NO;

animation.fillMode = kCAFillModeForwards;

animation.timingFunction = [CAMediaTimingFunctionfunctionWithName: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, 0, 0, direction);

CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"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;

}

转自:http://zhangmingwei.iteye.com/blog/2101782

iOS 简单的动画自定义方法(旋转、移动、闪烁等)的更多相关文章

  1. iOS - (简单平移动画/弹出View的使用)

    在iOS 开发中,使用平移动画的频率越来越高,给人的感觉就是很炫酷很流畅,起到增强用户体验的作用.在APP开发中实现动画效果有很多种方式,但我目前是使用较多的是平移动画,顺便也在此做一些小小的总结,大 ...

  2. iOS开发UI篇—iOS开发中三种简单的动画设置

    iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...

  3. iOS UI-三种简单的动画设置

    一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView beginAnimations:nil context:nil]; //设置动画时长 ...

  4. iOS简单动画

    知识架构 CALayer 图层类 CABasicAnimation 基础动画 CAKeyFrameAnimation 帧动画 CATransition 转场动画 CAAnimationGroup 动画 ...

  5. IOS QuartzCore核心动画框架

    IOS QuartzCore核心动画框架 核心动画框架 使用核心动画需要引入的框架:#import CALayer: CoreAnimation CALayer就是UIView上的图层,很多的CALa ...

  6. iOS 开发之动画篇 - 从 UIView 动画说起

    毋庸置疑的:在iOS开发中,制作动画效果是最让开发者享受的环节之一.一个设计严谨.精细的动画效果能给用户耳目一新的效果,吸引他们的眼光 —— 这对于app而言是非常重要的. 本文作为动画文集的第一篇, ...

  7. iOS学习——核心动画

    iOS学习——核心动画 1.什么是核心动画 Core Animation(核心动画)是一组功能强大.效果华丽的动画API,无论在iOS系统或者在你开发的App中,都有大量应用.核心动画所在的位置如下图 ...

  8. iOS学习——核心动画之Layer基础

    iOS学习——核心动画之Layer基础 1.CALayer是什么? CALayer我们又称它叫做层.在每个UIView内部都有一个layer这样一个属性,UIView之所以能够显示,就是因为它里面有这 ...

  9. iOS开发-动画总结

    一.简介 IOS 动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide.Core Animation是IOS和OS X平台上负责图形渲染与动画的基 ...

随机推荐

  1. 闲扯 『 document.write 』

    初春的晚上,闲来无事,聊聊 document.write 方法. document.write 使用方式非常简单,把 "字符串化"(不好意思,这可能是我自己创造的名词)的 html ...

  2. jQuery学习笔记(四):attr()与prop()的区别

    这一节针对attr()与prop()之间的区别进行学习. 先看看官方文档是如何解释两者之间功能差异的: attr() Get the value of an attribute for the fir ...

  3. Google 面试

    坚持完成这套学习手册,你就可以去 Google 面试了 系统 指针 value Google 面试 阅读10266   本文为掘金投稿,译文出自:掘金翻译计划 原文地址:Google Intervie ...

  4. fir2(n,f,m)

    编辑 函数fir2用来设计多通带任意响应FIR滤波器,该滤波器的幅频特性由向量对f和m确定,f为归一化频率向量,m为对应频率点上的幅度.当设计的滤波器在频率为π的幅度响应不是0时,滤波器的阶数n为偶数

  5. MATLAB中plot()画图的颜色线型和希腊字母参数设置

    y         黄色           ·             点线      m         粉红           ○             圈线      c          ...

  6. mysql创建触发器

    触发器语句只有一句话 可以省略begin和end CREATE trigger `do_praise` after insert on praise for each row update post ...

  7. iOS-- 重要的链接

    面试题: http://www.jianshu.com/p/6a57c6e902e8 富文本: http://www.cnblogs.com/jys509/p/5018027.html

  8. wsdl说明书

    WSDL文档的结构实例解析 <?xml version="1.0" encoding="UTF-8"?> <definitions xmlns ...

  9. Socket,TCP/IP,UDP,HTTP,FTP

    1.Socket:套接字,是传输层协议的一种编程API 作用:用于描述IP地址和端口,区分来自不同应用程序的通信,实现数据传输的并发服务 JDK  Socket:在java.net包下有两个类Sock ...

  10. Swift开发小技巧--自定义转场动画

    自定义转场动画 个人理解为重写了被弹出控制器的modal样式,根据自己的样式来显示modal出来的控制器 例:presentViewController(aVC, animated: true, co ...