IOS中的动画——Core Animation
| 一、基础动画 CABasicAnimation |
//初始化方式
CABasicAnimation * cabase=[CABasicAnimation animation];
//通过keyPath设置需要实现动画的属性,此处设为bounds
cabase.keyPath=@"bounds";
//通过toValue设置动画结束时候的状态
cabase.toValue=[NSValue valueWithCGRect:CGRectMake(, , , )];
//通过byValue设置每次改变的范围
cabase.byValue=[NSValue valueWithCGRect:CGRectMake(, , , )];
//设置开始时候的状态
cabase.fromValue=[NSValue valueWithCGPoint:CGPointMake(, )]; //设置动画持续的时间
cabase.duration=;
//保存动画
cabase.fillMode=kCAFillModeForwards;
//保存设置不取消
cabase.removedOnCompletion=NO;
[_layer addAnimation:cabase forKey:nil];
案例:通过基础动画实现仿射变换动画
CABasicAnimation * cabase=[CABasicAnimation animation];
cabase.keyPath=@"transform";
cabase.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(, , )];
cabase.duration=;
cabase.fillMode=kCAFillModeForwards; cabase.removedOnCompletion=NO;
[_layer addAnimation:cabase forKey:nil];
| 二、关键帧动画 |
//初始化方式
CAKeyframeAnimation * keyfram=[CAKeyframeAnimation animation];
//通过keyPath设置需要实现动画的属性,此处设为position
keyfram.keyPath=@"position";
//设置动画的需要经过的点
CGPoint p1=CGPointZero;
CGPoint p2=CGPointMake(, );
CGPoint p3=CGPointMake(, );
CGPoint p4=CGPointMake(, );
CGPoint p5=CGPointZero; NSValue * v1=[NSValue valueWithCGPoint:p1];
NSValue * v2=[NSValue valueWithCGPoint:p2];
NSValue * v3=[NSValue valueWithCGPoint:p3];
NSValue * v4=[NSValue valueWithCGPoint:p4];
NSValue * v5=[NSValue valueWithCGPoint:p5];
//将对应的值添加到动画并且设置动画保留
keyfram.values=@[v1,v2,v3,v4,v5];
keyfram.duration=;
keyfram.fillMode=kCAFillModeForwards;
keyfram.removedOnCompletion=NO;
[_layer addAnimation:keyfram forKey:nil];
案例:通过关键帧动画实现图片摇摆
CAKeyframeAnimation * anima=[CAKeyframeAnimation animation];
//通过设置放射变换的角度来实现
anima.keyPath=@"transform.rotation";
float p1=/180.0*M_PI;
anima.duration=0.2;
anima.values=@[@(-p1),@(p1),@(-p1)];
anima.fillMode=kCAFillModeForwards;
anima.removedOnCompletion=NO;
anima.repeatCount=MAXFLOAT;
[_layer addAnimation:anima forKey:nil];
_layer.transform=CATransform3DMakeRotation(M_PI, , , );
| 三、转场动画 |
//初始化方式
CATransition * tran=[CATransition animation];
//设置动画效果
tran.type=@"rippleEffect"; //常用效果
kCATransitionFade
kCATransitionMoveIn
kCATransitionPush
kCATransitionReveal //设置动画方向
tran.subtype=kCATransitionFromLeft; //动画方向
kCATransitionFromRight
kCATransitionFromLeft
kCATransitionFromTop
kCATransitionFromBottom //设置动画保留以及动画时长
tran.fillMode=kCAFillModeForwards;
tran.removedOnCompletion=NO;
tran.duration=;
[self.myImageView.layer addAnimation:tran forKey:nil];
| 四、UIView封装动画 |
UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画支持。执行动画所需要的工作由UIView类自动完成,但仍要在希望执行动画时通知视图,为此需要将改变属性的代码放在[UIViewbeginAnimations:nil context:nil]和[UIView commitAnimations]之间
1、常见方法解析:
//设置动画代理
+ (void)setAnimationDelegate:(id)delegate //设置当动画即将开始时,执行delegate对象的selector,并且把beginAnimations:context:中传入的参数传进selector
+(void)setAnimationWillStartSelector:(SEL)selector //设置动画结束时调用方法
+ (void)setAnimationDidStopSelector:(SEL)selector //设置动画持续时间
+(void)setAnimationDuration:(NSTimeInterval)duration //设置动画延迟
+ (void)setAnimationDelay:(NSTimeInterval)delay //设置动画开始时间
+ (void)setAnimationStartDate:(NSDate *)startDate //设置动画节奏
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve //设置动画重复次数
+ (void)setAnimationRepeatCount:(float)repeatCount //如果设置为YES,代表动画每次重复执行的效果会跟上一次相反
+(void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses // 设置视图view的过渡效果, transition指定过渡类型, cache设置YES代表使用视图缓存,性能较好
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache
2、案例
//旋转动画
[UIView beginAnimations:@"roate" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelegate:self];
_view.transform=CGAffineTransformRotate(_view.transform, M_PI_2);
[UIView setAnimationDidStopSelector:@selector(endAnimate)];
[UIView commitAnimations];
//转场动画
[UIView beginAnimations:@"transition" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_mainView cache:YES];
[UIView setAnimationDuration:1.5];
NSInteger index1=[_mainView.subviews indexOfObject:_view];
NSInteger index2=[_mainView.subviews indexOfObject:_view2];
[_mainView exchangeSubviewAtIndex:index1 withSubviewAtIndex:index2];
[UIView commitAnimations];
出处:http://www.cnblogs.com/jerehedu/
本文版权归烟台杰瑞教育科技有限公司和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
IOS中的动画——Core Animation的更多相关文章
- iOS 图形图像动画 Core Animation
//Core Animation #define WeakSelf __weak __typeof(self) weakSelf = self #define StrongSelf __strong ...
- iOS中的动画
iOS中的动画 Core Animation Core Animation是一组非常强大的动画处理API,使用它能做出非常绚丽的动画效果,而且往往是事半功倍,使用它需要添加QuartzCore .fr ...
- iOS中的动画(转载)
iOS中的动画 最近两天没事在慢慢学习一些动画,好多东西长时间不用都给忘了,找到一篇介绍很详细的文章就粘贴了过来以备复习,原文地址:https://my.oschina.net/aofe/blog/ ...
- iOS 核心动画 Core Animation浅谈
代码地址如下:http://www.demodashi.com/demo/11603.html 前记 关于实现一个iOS动画,如果简单的,我们可以直接调用UIView的代码块来实现,虽然使用UIVie ...
- (转)iOS动画Core Animation
文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...
- iOS开发之核心动画(Core Animation)
1.概述 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架< ...
- IOS中的动画菜单
SvpplyTable(可折叠可张开的菜单动画) 允许你简单地创建可折叠可张开的菜单动画效果,灵感来自于Svpply app.不同表格项目使用JSON定义,你可以定义每个菜单项和任何子菜单,为每个项目 ...
- 核心动画——Core Animation
一. CALayer (一). CALayer简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比方一个button.一个文本标签.一个文本输入框.一个图标等等.这些都是UIView ...
- unity从模型中抽取动画文件(animation)
http://www.cnblogs.com/leng-yuye/archive/2013/01/11/2856144.html 由于模型是由第三方的软件制作的,用unity不能直接编辑模型里的动画文 ...
随机推荐
- JAVAEE——宜立方商城08:Zookeeper+SolrCloud集群搭建、搜索功能切换到集群版、Activemq消息队列搭建与使用
1. 学习计划 1.solr集群搭建 2.使用solrj管理solr集群 3.把搜索功能切换到集群版 4.添加商品同步索引库. a) Activemq b) 发送消息 c) 接收消息 2. 什么是So ...
- Django ORM训练专题
图书信息系统 表结构设计 # 书 class Book(models.Model): title = models.CharField(max_length=32) publish_date = mo ...
- 20162303石亚鑫 第十二周hash补充博客
要求 利用除留余数法为下列关键字集合的存储设计hash函数,并画出分别用开放寻址法和拉链法解决冲突得到的空间存储状态(散列因子取0.75) 关键字集合:85,75,57,60,65,(你的8位学号相加 ...
- [POJ1082]Calendar Game
题目大意: 日历上博弈,从给定的日期,按照下述规则跳转日期: 1.跳到第二天: 2.调到下个月相同的日期(如果没有就不能跳转). 刚刚好跳到2001年11月4日的人胜,跳转时不能跳到2001年11月4 ...
- BZOJ 1007: [HNOI2008]水平可见直线 栈/计算几何
1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MB 题目连接 http://www.lydsy.com/JudgeOnline ...
- PostgreSQL增强版命令行客户端(pgcli)
效果: 安装: https://www.pgcli.com/install 官网: https://www.pgcli.com/
- Namespace declaration statement has to be the very first statement in the script
php 中 Namespace declaration statement has to be the very first statement in the script 错误解决方法: 在PHP文 ...
- 各种SSD SMART 信息 转
intel SSD Toolbox SMART信息 解释:03 – Spin Up Time (磁头加载时间)The average time it takes the spindle to spin ...
- HTTP的KeepAlive是开启还是关闭?
HTTP的KeepAlive是开启还是关闭? http://itindex.net/detail/50719-http-keepalive 1.KeepAlive的概念与优势 HTTP的KeepAli ...
- clip-path 教程:使用 CSS 中的 clip-path 轻松实现多边形
作为一个前端开发,一个主要的工作就是来实现设计师设计的UI界面.而在UI界面中,各种各样的形状元素应用则是随处可见,比如三角形: 以前碰到这种形状的时候,会使用各种黑科技的技巧,比如使用CSS中的bo ...