iOS简单动画效果:闪烁、移动、旋转、路径、组合
- #define kDegreesToRadian(x) (M_PI * (x) / 180.0)
- #define kRadianToDegrees(radian) (radian*180.0)/(M_PI)
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- self.title = @"测试动画";
- self.view.backgroundColor = [UIColorlightGrayColor];
- myTest1 = [[UILabelalloc]initWithFrame:CGRectMake(10, 100, 60, 40)];
- myTest1.backgroundColor = [UIColorblueColor];
- myTest1.textAlignment = NSTextAlignmentCenter;
- myTest1.text = @"张明炜";
- myTest1.textColor = [UIColorwhiteColor];
- [self.viewaddSubview: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:[selfrotation:2degree:kRadianToDegrees(90) direction:1repeatCount:MAXFLOAT] forKey:nil];
- }
- #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 *)moveX:(float)time X:(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 = [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 = [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, 0, 0, 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简单动画效果:闪烁、移动、旋转、路径、组合的更多相关文章
- iOS各种动画效果
ios各种动画效果 最普通动画: //开始动画 [UIView beginAnimations:nil context:nil]; //设定动画持续时间 [UIView setAnimationDu ...
- 原生JS封装简单动画效果
原生JS封装简单动画效果 一致使用各种插件,有时候对原生JS陌生了起来,所以决定封装一个简单动画效果,熟悉JS原生代码 function animate(obj, target,num){ if(ob ...
- ios开发之--简单动画效果的添加
记录一个简单的动画效果,自己写的,很简单,仅做记录. 附一个demo的下载地址: https://github.com/hgl753951/hglTest.git 代码如下: 1,准备 BOOL _i ...
- iOS添加到购物车的简单动画效果
#pragma mark - 添加到购物车的动画效果 // huangyibiao - (void)addAnimatedWithFrame:(CGRect)frame { // 该部分动画 以sel ...
- iOS 转盘动画效果实现
代码地址如下:http://www.demodashi.com/demo/11598.html 近期公司项目告一段落,闲来无事,看到山东中国移动客户端有个转盘动画挺酷的.于是试着实现一下,看似简单,可 ...
- iOS的动画效果类型及实现方法
实现iOS漂亮的动画效果主要有两种方法, 一种是UIView层面的, 一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层也是使用CATransit ...
- iOS 帧动画之翻转和旋转动画
记录两个比较简单的动画,一个是翻转的动画,一个是旋转的动画. 旋转动画: 1 [UIView animateWithDuration:3 animations:^{ if (formView) { f ...
- iOS开动画效果之──实现 pushViewController 默认动画效果
在开发中,视图切换会常常遇到,有时我们不是基于导航控制器的切换,但实际开发中,有时需要做成push效果,下面将如何实现push和pop 默认动画效果代码实例: 一.push默认动画效果 CATrans ...
- jQuery之简单动画效果
1. show()显示动画 语法:show(speed,callback) Number/String,Function speend为动画执行时间,单位为毫秒.也可以为slow",&quo ...
随机推荐
- Zabbix实战-简易教程(4)--Server端安装
在数据库安装完成后,接着开始安装server端了.我们这里采用yum安装. 3.2.0 安装需求 ● PHP 5.6.18 ● curl 7.47.1 ● zabbix_server (Zabbix) ...
- Linux下自动化监控内存、存储空间!
距离上一次更新文章已经过去一段时间了,小编在这段时间因为一些琐事,加上身体生病不能及时更新文章,今天身体逐渐恢复就急忙来更新文章,今天思梦给大家带来的就是如何自动化监控我们的服务器一些基本的配置来保证 ...
- 记一次python的一些参数
isdigit把字符串转化为整数 用法 if xx.isdigit(): xx=int(xx) index创建一个小原组,用法print(a.index(b),b)从0开始
- CTF---密码学入门第六题 古典密码
古典密码分值:10 来源: 北邮天枢战队 难度:易 参与人数:5115人 Get Flag:1549人 答题人数:1783人 解题通过率:87% 密文内容如下{79 67 85 123 67 70 8 ...
- 【Java学习笔记之十一】Java中常用的8大排序算法详解总结
分类: 1)插入排序(直接插入排序.希尔排序) 2)交换排序(冒泡排序.快速排序) 3)选择排序(直接选择排序.堆排序) 4)归并排序 5)分配排序(基数排序) 所需辅助空间最多:归并排序 所需辅助空 ...
- bzoj:1681 [Usaco2005 Mar]Checking an Alibi 不在场的证明
Description A crime has been comitted: a load of grain has been taken from the barn by one of FJ's c ...
- 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】
Colorful Tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- bzoj usaco 金组水题题解(2.5)
bzoj 2197: [Usaco2011 Mar]Tree Decoration 树形dp..f[i]表示处理完以i为根的子树的最小时间. 因为一个点上可以挂无数个,所以在点i上挂东西的单位花费就是 ...
- oracle erp 表结构
BOM模块常用表结构 表名: bom.bom_bill_of_materials 说明: BOM清单父项目 BILL_SEQUENCE_ID NUMBER 清单序号(关键字)ASSEMBLY_ITEM ...
- JAVA虚拟机之对象探秘
上一章主要写到了JVM中运行时数据区域各个部分的功能及其作用.上一章说到了对象是分配在堆上面的,所以接下来我们写到对象在堆内存中是如何创建.如何布局.如何访问.1. 对象的创建 在java程序中对象的 ...