一、基础动画 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的更多相关文章

  1. iOS 图形图像动画 Core Animation

    //Core Animation #define WeakSelf __weak __typeof(self) weakSelf = self #define StrongSelf __strong ...

  2. iOS中的动画

    iOS中的动画 Core Animation Core Animation是一组非常强大的动画处理API,使用它能做出非常绚丽的动画效果,而且往往是事半功倍,使用它需要添加QuartzCore .fr ...

  3. iOS中的动画(转载)

    iOS中的动画  最近两天没事在慢慢学习一些动画,好多东西长时间不用都给忘了,找到一篇介绍很详细的文章就粘贴了过来以备复习,原文地址:https://my.oschina.net/aofe/blog/ ...

  4. iOS 核心动画 Core Animation浅谈

    代码地址如下:http://www.demodashi.com/demo/11603.html 前记 关于实现一个iOS动画,如果简单的,我们可以直接调用UIView的代码块来实现,虽然使用UIVie ...

  5. (转)iOS动画Core Animation

    文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...

  6. iOS开发之核心动画(Core Animation)

    1.概述 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架< ...

  7. IOS中的动画菜单

    SvpplyTable(可折叠可张开的菜单动画) 允许你简单地创建可折叠可张开的菜单动画效果,灵感来自于Svpply app.不同表格项目使用JSON定义,你可以定义每个菜单项和任何子菜单,为每个项目 ...

  8. 核心动画——Core Animation

    一. CALayer (一). CALayer简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比方一个button.一个文本标签.一个文本输入框.一个图标等等.这些都是UIView ...

  9. unity从模型中抽取动画文件(animation)

    http://www.cnblogs.com/leng-yuye/archive/2013/01/11/2856144.html 由于模型是由第三方的软件制作的,用unity不能直接编辑模型里的动画文 ...

随机推荐

  1. JAVAEE——宜立方商城09:Activemq整合spring的应用场景、添加商品同步索引库、商品详情页面动态展示与使用缓存

    1. 学习计划 1.Activemq整合spring的应用场景 2.添加商品同步索引库 3.商品详情页面动态展示 4.展示详情页面使用缓存 2. Activemq整合spring 2.1. 使用方法 ...

  2. request.get_full_path() 和request.path区别

    1. 都是获取request 请求的url路径 2. request.get_full_path() -- 获取当前url,(包含参数) 请求一个http://127.0.0.1:8000/200/? ...

  3. sql分组排序取top

    写法1: use anypay; select tr.* from (select task_code, max(created_at) as cal from task_log group by t ...

  4. [BZOJ5293][BJOI2018]求和(倍增)

    裸的树上倍增. #include<cstdio> #include<cstring> #include<algorithm> #define rep(i,l,r) ...

  5. py脚本打包exe可执行文件

    python3以上版本打包exe需要扩展软件:cx_freeze 下载地址:http://cx-freeze.sourceforge.net/ 1)安装后在\Python32\Scripts\cxfr ...

  6. Codeforces Round #294 (Div. 2)C - A and B and Team Training 水题

    C. A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input ...

  7. UVALive 5058 Counting BST 数学

    B - Counting BST Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  8. Syncthing -- 开源的云储存和同步服务工具

    Syncthing  -- an open-source file synchronization client/server application Syncthing是一个开源的云存储和同步服务工 ...

  9. [MySql]锁表与解锁

    摘要 为啥会出现锁表的情况?锁表会导致数据表的其他操作超时,频繁的插入修改查询很容易出现锁表的情况.如果遇到这种情况,临时的解决办法,可以通过下面的方式进行解锁.如果长期有效的解决,那么就需要优化项目 ...

  10. MsDepSvc 启动失败

    MsDepSvc 使用80端口,用于 Microsoft Web Deploy 3.6 的远程代理服务. 如果80端口被占用,则启动失败.我的是被phpstudy软件占用,所以启动失败.