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的装饰方法对这些动画操作进行简化等.在今天的文章里您可以看 ...
随机推荐
- plist文件的读取
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"cinemalist" ofType:@"pl ...
- [开发笔记]-使用jquery获取url及url参数的方法
使用jquery获取url以及使用jquery获取url参数是我们经常要用到的操作 1.jquery获取url很简单,代码如下: window.location.href; 其实只是用到了javasc ...
- Linux-守护进程的实现
Some basic rules to coding a daemon prevent unwanted interactions from happening. We state these rul ...
- HDU 2586 LCA
题目大意: 多点形成一棵树,树上边有权值,给出一堆询问,求出每个询问中两个点的距离 这里求两个点的距离可以直接理解为求出两个点到根节点的权值之和,再减去2倍的最近公共祖先到根节点的距离 这是自己第一道 ...
- 戴文的Linux内核专题:07内核配置(3)
转自Linux中国 OK,我们还继续配置内核.还有更多功能等待着去配置. 下一个问题(Enable ELF core dumps (ELF_CORE))询问的是内核是否可以生成内核转储文件.这会使内核 ...
- 使用windows远程桌面连接Windows Azure中的Ubuntu虚拟机
1.创建ubuntu虚拟机,这里同样不再赘述,创建过程和创建Windows虚拟机基本一样,只是登录可以选择密钥注入或者用户名密码(为了方便我选择了用户名密码认证),创建完成后,查看虚拟机详情中的端口信 ...
- iis提示“另一个程序正在使用此文件,进程无法访问。(异常来自HRESULT:0x80070020)
看看IIS的网站,惊人的发现default web site是停止状态.印象中没有停止它啊.右键->管理网站->启动.点击启动后居然弹出:“另一个程序正在使用此文件,进程无法访问.(异常来 ...
- 关押罪犯(noip2010)
解法: (1)搜索(30分) (2)二分(此题属于最大值最小问题) (3)贪心+并查集 下面着重说一下“贪心+并查集” 因为有A.B两座监狱,每个犯人不是在A,就是在B监狱. 至于每个犯人在那个监狱, ...
- AutoReleasePool 和 ARC 以及Garbage Collection
AutoReleasePool autoreleasepool并不是总是被auto 创建,然后自动维护应用创建的对象. 自动创建的情况如下: 1. 使用NSThread的detachNewThread ...
- jQuery tab plugin
/* www.keleyi.com/ */ ; (function ($) { $.fn.extend({ Tabs: function (options) { // 处理参数 options = $ ...