iOS中动画的简单使用
iOS中的动画右两大类1.UIView的视图动画2.Layer的动画 UIView的动画也是基于Layer的动画
动画的代码格式都很固定
1.UIView动画
一般方式
[UIView beginAnimations:@"ddd" context:nil];//设置动画
[UIView commitAnimations]; //提交动画
这两个是必须有的,然后在两句的中间添加动画的代码
[UIView beginAnimations:@"ddd" context:nil];//设置动画 ddd为动画名称
[UIView setAnimationDuration:3];//定义动画持续时间
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //setAnimationCurve来定义动画加速或减速方式
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.window cache:YES];
//设置动画的样式 forView为哪个view实现这个动画效果
[UIView setAnimationDelay:3]; //设置动画延迟多久执行
[UIView setAnimationDelegate:self]; //设置动画的代理 实现动画执行前后的方法 在commitAnimation之前设置
[UIView setAnimationDidStopSelector:@selector(stop)];//设置动画结束后执行的方法
[UIView setAnimationWillStartSelector:@selector(star)];//设置动画将要开始执行的方法
[UIView commitAnimations]; //提交动画
typedef enum {
UIViewAnimationTransitionNone, //普通状态
UIViewAnimationTransitionFlipFromLeft, //从左往右翻转
UIViewAnimationTransitionFlipFromRight, //从右往左翻转
UIViewAnimationTransitionCurlUp, //向上翻页
UIViewAnimationTransitionCurlDown, //向下翻页
} UIViewAnimationTransition;
typedef enum {
UIViewAnimationCurveEaseInOut,
UIViewAnimationCurveEaseIn,
UIViewAnimationCurveEaseOut,
UIViewAnimationCurveLinear
} UIViewAnimationCurve;
[UIView beginAnimations:@"ddd" context:nil]; //设置动画
view.frame = CGRectMake(200, 200, 100, 100);
[UIView commitAnimations]; //提交动画
当view从本来的frame移动到新的frame时会慢慢渐变 而不是一下就完成了 中间也可以添加到上面那段中间 只是多种效果重叠
以下这些也可以加到 [UIView beginAnimations:@"ddd" context:nil]; [UIView commitAnimations];之间
view.transform = CGAffineTransformMakeTranslation(10, 10);//设置偏移量 相对于最初的 只能偏移一次
view.transform = CGAffineTransformTranslate(view.transform, 10, 10); //设置偏移量 偏移多次
self.view.transform = CGAffineTransformMakeRotation(M_PI);//设置旋转度 只能旋转一次
self.view.transform = CGAffineTransformRotate(self.view.transform, M_PI); //旋转多次
self.view.transform = CGAffineTransformMakeScale(1.1, 1.1); //设置大小 只能改变一次 数值时相对于本来的几倍
self.view.transform = CGAffineTransformScale(self.view.transform, 1.1, 1.1);//改变多次
self.view.transform = CGAffineTransformIdentity;//回到当初的样子 执行一次
self.view.transform = CGAffineTransformInvert(self.view.transform);//得到相反的样子 大小 方向 位置执行多次
Block方式
[UIView animateWithDuration:3 animations:^(void){
//这里相当于在begin和commint之间
}completion:^(BOOL finished){
//这里相当于动画执行完成后要执行的方法,可以继续嵌套block
}];
2.CAAnimation
需要添加库,和包含头文件
caanimation有多个子类
CABasicAnimation
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
//@""里的字符串有多种,可以自己找相关资料,一定要填对,动画才会执行 opacity设置透明度 bounds.size设置大小
[animation setFromValue:[NSNumber numberWithFloat:1.0]]; //设置透明度从几开始
[animation setToValue:[NSNumber numberWithFloat:0.3]];//设置透明度到几结束
[animation setDuration:0.1]; //设置动画时间
[animation setRepeatCount:100000];//设置重复时间
[animation setRepeatDuration:4]; //会限制重复次数
[animation setAutoreverses:NO];//设置是否从1.0到0.3 再从0.3到1.0 为一次 如果设置为NO则 1.0到0.3为一次
[animation setRemovedOnCompletion:YES]; //完成时移出动画 默认也是
[view.layer addAnimation:animation forKey:@"abc"];//执行动画
CAKeyframeAnimation
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];//设置view从初始位置经过一系列点
NSArray *postionAraay = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(100, 20)], [NSValue valueWithCGPoint:CGPointMake(40, 80)],[NSValue valueWithCGPoint:CGPointMake(30, 60)],[NSValue valueWithCGPoint:CGPointMake(20, 40)],[NSValue valueWithCGPoint:CGPointMake(0, 100)],nil];//设置点
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.3],[NSNumber numberWithFloat:0.5],[NSNumber numberWithFloat:0.6],[NSNumber numberWithFloat:0.1],[NSNumber numberWithFloat:1.0], nil]; //设置移动过程的时间
[animation setKeyTimes:times];
[animation setValues:postionAraay];
[animation setDuration:5]; //设置动画时间
[bigImage.layer addAnimation:animation forKey:@"dd"]; //执行动画
CATransition
CATransition *animation = [CATransition animation];
animation.duration = 0.5f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
/*
kCATransitionFade;
kCATransitionMoveIn;
kCATransitionPush;
kCATransitionReveal;
*/
/*
kCATransitionFromRight;
kCATransitionFromLeft;
kCATransitionFromTop;
kCATransitionFromBottom;
*/
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromBottom;
[view.layer addAnimation:animation forKey:animation];
type也可以直接用字符串
/*
cube
suckEffect 卷走
oglFlip 翻转
rippleEffect 水波
pageCurl 翻页
pageUnCurl
cameraIrisHollowOpen
cameraIrisHollowClose
*/
iOS中动画的简单使用的更多相关文章
- 转载 -- iOS中SDK的简单封装与使用
一.功能总述 在博客开始的第一部分,我们先来看一下我们最终要实现的效果.下图中所表述的就是我们今天博客中要做的事情,下方的App One和App Two都植入了我们将要封装的LoginSDK, 两个A ...
- iOS 中多线程的简单使用
iOS中常用的多线程操作有( NSThread, NSOperation GCD ) 为了能更直观的展现多线程操作在SB中做如下的界面布局: 当点击下载的时候从网络上下载图片: - (void)loa ...
- 在iOS中实现一个简单的画板App
在这个随笔中,我们要为iPhone实现一个简单的画板App. 首先需要指出的是,这个demo中使用QuarzCore进行绘画,而不是OpenGL.这两个都可以实现类似的功能,区别是OpenGL更快,但 ...
- iOS 中CoreData的简单使用
原文链接:http://www.jianshu.com/p/4411f507dd9f 介绍:本文介绍的CoreData不在AppDelegate中创建,在程序中新建工程使用,即创建本地数据库,缓存数据 ...
- iOS CATransition 动画的简单使用
下面是实现的代码 //选择动画 - (IBAction)selectAnimationTypeButton:(id)sender { UIButton *button = sender; animat ...
- ios中通知的简单使用
通知的机制是一对多,而block和delegate的机制是一对一,通知是好用,但小伙伴么要记得通知比较耗性能哦~~~ 谁要发送消息,谁就发出通知,谁要接受消息,谁就销毁通知. 下面直接来看代码: // ...
- iOS 项目中的NSNotification简单使用
iOS中NSNotification的简单使用 好久没有写过博客了,总是遇到问题查一下,今天查的又是一个老问题,想了想,还是记录一下!今天在项目开发中遇到一个配置及时性处理的问题,想了想之后决定用通知 ...
- IOS之动画
IOS之动画 15.1 动画介绍 15.2 Core Animation基础 15.3 隐式动画 15.4 显式动画 15.5 关键帧显式动画 15.6 UIView级别动画 15.1 动画介绍 ...
- IOS 动画专题 --iOS核心动画
iOS开发系列--让你的应用“动”起来 --iOS核心动画 概览 通过核心动画创建基础动画.关键帧动画.动画组.转场动画,如何通过UIView的装饰方法对这些动画操作进行简化等.在今天的文章里您可以看 ...
随机推荐
- AudioManager音频管理器
AudioManager音频管理器提供了如下几种常用方法来控制手机音频: 1.adjustStreamVolume(int StreamType,int direction,int flgs):调整手 ...
- js基础之arguments、css
arguments就是一个包含传入的参数的数组对象 栗子一: function sum(){ var result=0; for(var i=0;i<arguments.length;i++){ ...
- ZOJ 3644 Kitty's Game dfs,记忆化搜索,map映射 难度:2
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 从点1出发,假设现在在i,点数为sta,则下一步的点数必然不能是sta的 ...
- 3.精通前端系列技术之深入学习Jquery(一)
使用Jquery的好处: •简化JS的复杂操作 •不再需要关心兼容性(原生js获取元素样式.事件需要做兼容性) •提供大量实用方法 1.选择网页元素 <!DOCTYPE html PUBLIC ...
- [vijos P1034] 家族
寒假给自己定的第一个目标就是把并查集,Tarjan之类搞会.翻了翻笔记,发现并查集是2012年的6月30日学的…早就忘光了…今天敲题目的时候也吃了不少的亏呢… 家族这一题就是并查集的标准题,第一次提交 ...
- Cisco IOS debug command reference Command A through D
debug aaa accounting through debug auto-config debug aaa accounting : to display information on acco ...
- 多功能节点连线绘图控件Nevron Diagram for .NET使用方法及下载地址
Nevron Diagram for .NET是一个功能强大,世界上顶级的.NET图表控件.可扩展的图形报表构架,可以帮您创建功能丰富的Winforms及Webforms图表解决方案.这个产品构建于N ...
- iOS开发中关于nslog的几种流行做法小结
不管哪种方法,都必须在PCH文件中做下宏定义 DEBUG和RELEASE要分开,RELEASE时log打印要取消 方法一:简单直接,用几行代码搞定,简洁但功能少 #ifdef DEBUG #defin ...
- python建立pip.ini
pip 是python的包管理器工具,类似linux的apt-get.yum包管理器,主要是用来进行安装python库, pip默认从官方源pypi.python.org下载数据,国内速度相对比较慢, ...
- 系统的 host文件的作用
有些用户可能已经注意到,我们在上网时除了可使用常规的 http://www.xxx.com或http://www.xxx.com.cn等形式的网站域名之外,还可以使用类似于“202.106.184.2 ...