一. CABasicAnimation (基础动画)

移位:

    CABasicAnimation *animation = [CABasicAnimation animation];
//keyPath指定动画类别,position表示移位
animation.keyPath = @"position";
//移动到x=200,y=200的位置
animation.toValue = [NSValue valueWithCGPoint:CGPointMake(, )];
animation.duration = ;
//动画执行完毕后不删除动画
animation.removedOnCompletion = NO;
//保持最新的状态
animation.fillMode = @"forwards";
//添加动画
[self.layer addAnimation:animation forKey:nil];

缩放:

    CABasicAnimation *animation = [CABasicAnimation animation];
//keyPath指定动画类别,bounds表示缩放
animation.keyPath = @"bounds";
//缩放到width=50,height=50
animation.toValue = [NSValue valueWithCGRect:CGRectMake(, , , )];
animation.duration = ;
//动画完成不删除动画
animation.removedOnCompletion = NO;
//保持最新的状态
animation.fillMode = @"forwards"; [self.layer addAnimation:animation forKey:nil];

旋转:

    CABasicAnimation *animation = [CABasicAnimation animation];
//keyPath指定动画类别,transform表示旋转
animation.keyPath = @"transform";
//沿x,y轴顺时针旋转45度
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, , , )];
animation.duration = ;
animation.removedOnCompletion = NO;
animation.fillMode = @"forwards"; [self.layer addAnimation:animation forKey:nil];

二.  CAKeyframeAnimation (关键帧动画)

    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

    anim.keyPath = @"position";
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
anim.duration = 2.0; //设置圆形轨迹,并绕圆形轨迹移动
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddEllipseInRect(path, NULL, CGRectMake(, , , ));
anim.path = path;
CGPathRelease(path); // 设置动画的执行节奏
// kCAMediaTimingFunctionEaseInEaseOut : 一开始比较慢, 中间会加速, 临近结束的时候, 会变慢
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.delegate = self;
[anim setValue:@"aaa" forKey:@"TAG"];
[self.layer addAnimation:anim forKey:nil];

设置代理的回调方法,让动画结束后弹出提示

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSString *strTag = [anim valueForKey:@"TAG"];
if ([strTag isEqualToString:@"aaa"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Animation Done" message:@"动作完成" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}
}

三. CATransition(转场动画)

(1)视图跳转

    _newView = [[UIView alloc] init];
_newView.frame = CGRectMake(, , , );
[self.view addSubview:_newView]; UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(, , , );
view1.backgroundColor = [UIColor yellowColor];
[_newView addSubview:view1]; UIView *view2 = [[UIView alloc] init];
view2.frame = CGRectMake(, , , );
view2.backgroundColor = [UIColor greenColor];
[_newView addSubview:view2];

添加转场按钮事件处理:

- (IBAction)exchangeView {
// 转场动画
CATransition *transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = @"pageCurl";
transition.subtype = kCATransitionFromRight;
transition.duration = ;
[_newView exchangeSubviewAtIndex: withSubviewAtIndex:];
[_newView.layer addAnimation:transition forKey:@"myAnimation"];
}

(2)控制器跳转

- (IBAction)pushView {
CATransition *transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//立体动画效果
transition.type = @"cube";
[self.navigationController.view.layer addAnimation:transition forKey:@"navAnimation"];
TestViewController *testVC = [[TestViewController alloc] init];
[self.navigationController showViewController:testVC sender:nil];
}

四. CAAnimationGroup (组合动画)

    //添加图片
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"curry.jpg"]];
imgView.frame = CGRectMake(, , imgView.frame.size.width, imgView.frame.size.height);
[self.view addSubview:imgView]; //贝塞尔曲线路径
UIBezierPath *movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:CGPointMake(10.0, 10.0)];
[movePath addQuadCurveToPoint:CGPointMake(, ) controlPoint:CGPointMake(, )]; //以下必须导入QuartzCore包
//关键帧动画(位置)
CAKeyframeAnimation * posAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
posAnim.path = movePath.CGPath;
posAnim.removedOnCompletion = YES; //缩放动画
CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scaleAnim.removedOnCompletion = YES; //透明动画
CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
opacityAnim.removedOnCompletion = YES; //动画组
CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:posAnim, scaleAnim, opacityAnim, nil];
animGroup.duration = ; [imgView.layer addAnimation:animGroup forKey:nil];

iOS Core Animation学习总结(3)--动画的基本类型的更多相关文章

  1. iOS Core Animation学习总结(1)--CALayer常用属性

    图层是core animation的基础, UIView之所以能显示在屏幕上,靠的是其内部的这个图层,即每个UIView 都有 CALayer,可通过UIView.layer或者[UIView lay ...

  2. iOS Core Animation学习总结(2)--实现自定义图层

    一. 创建图层继承于CALayer,并在子类实现drawInContext方法 @interface CTLayer : CALayer @end @implementation CTLayer -( ...

  3. 转 iOS Core Animation 动画 入门学习(一)基础

    iOS Core Animation 动画 入门学习(一)基础 reference:https://developer.apple.com/library/ios/documentation/Coco ...

  4. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

  5. Core Animation学习总结

    文件夹: The Layer Beneath The Layer Tree(图层树) The Backing Image(寄宿层) Layer Geometry(图层几何学) Visual Effec ...

  6. iOS Core Animation 简明系列教程

    iOS Core Animation 简明系列教程  看到无数的CA教程,都非常的难懂,各种事务各种图层关系看的人头大.自己就想用通俗的语言翻译给大家听,尽可能准确表达,如果哪里有问题,请您指出我会尽 ...

  7. 使用Core Animation对象来实现动画

    转载保留原文地址:http://blog.csdn.net/kqjob/article/details/10417461,转载的 在iOS中如果使用普通的动画则可以使用UIKit提供的动画方式来实现, ...

  8. iOS Core Animation 动画 入门学习(一)基础

    reference:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide ...

  9. IOS Core Animation Advanced Techniques的学习笔记(五)

    第六章:Specialized Layers   类别 用途 CAEmitterLayer 用于实现基于Core Animation粒子发射系统.发射器层对象控制粒子的生成和起源 CAGradient ...

随机推荐

  1. [html]HTML <form> 标签的 enctype 属性

  2. mysql之select+五种子句的理解

    select 可以包含很复杂,很丰富的逻辑,最能考验一个人的逻辑思维能力和sql语句的掌握程度,我是这么认为,以前的很多次面试几乎都死在它手上,所以才有了今天的这篇日志,下定决心把它学好. where ...

  3. C#中反射的使用(How to use reflect in CSharp)(1)

    最近想做一个插件式的软件给公司的监控用,初步的想法是使用C#去反射Dll,Invoke其中的方法.此文仅供开发参考,不涉及原理,98%的代码以及2%的废话. 测试Solution是这么建的(.NET ...

  4. lunix机器的jdk安装

    本来不想写这篇博客的,写在这儿只是作为自己的笔记,jdk安装了千万编,但是踩过的坑老是不记,看别人的博客又各种不爽,所有索性自己写一个得了.老规矩,无图. Oracle版本的jdk下载地址:http: ...

  5. WinFrom 安装包制作

    1.添加安装向导项目打开文件系统界面,选择应用程序文件夹.在右侧右击->添加->文件,把程序需要的文件都添加进来. 2.右击程序集->创建快捷方式.右击快捷方式->属性窗口-& ...

  6. 在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke。

    本文转载:http://blog.csdn.net/playing9c/article/details/7471918 http://blog.csdn.net/beelinkerlidejun/ar ...

  7. Chord算法(原理)

    Chrod算法是P2P中的四大算法之中的一个,是有MIT(麻省理工学院)于2001年提出,其它三大算法各自是: CAN Pastry Tapestry Chord的目的是提供一种能在P2P网络高速定位 ...

  8. Design Pattern Explained 读书笔记二——设计模式序言

    设计模式的由来: 20 世纪 90 年代初,一些聪明的开发者偶然接触到 Alexander(Christopher Alexander 的建筑师) 有关模式的工作.他们非常想知道,在建筑学成立的理论, ...

  9. 已超过了锁请求超时时段。 (Microsoft SQL Server,错误: 1222)

    操作SQLServer数据库时.遇到这种问题:已超过了锁请求超时时段. (Microsoft SQL Server,错误: 1222) 经过查找材料了解为资源抢占,照成死锁,杀死进程就OK了.详细操作 ...

  10. C++ Primer 学习笔记_95_用于大型程序的工具 --多重继承与虚继承

    用于大型程序的工具 --多重继承与虚继承 引言: 大多数应用程序使用单个基类的公用继承,可是,在某些情况下,单继承是不够用的,由于可能无法为问题域建模,或者会对模型带来不必要的复杂性. 在这些情况下, ...