一. 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. iOS block并发

    多核运算 在iOS中concurrency编程的框架就是GCD(Grand Central Dispatch), GCD的使用非常简单.它把任务分派到不同的queue队列来处理.开发者把任务代码装到一 ...

  2. AVR ATMEGA8 串口USART

    avr串口配置很简单,配置就几个寄存器就可以进收发: 但有几点要搞明白的是: 1.串口一但被配置成功IO功能自动被占用,这点与LPC或STM8/32不同(需要寄存配置): 2.没有专门的串口开起或闭关 ...

  3. 依賴注入入門——Unity(一)

    參考資料http://blog.csdn.net/m13666368773/article/details/7802126 背景介紹 在设计模式中,尤其是结构型模式很多时候解决的就是对象间的依赖关系, ...

  4. Unable to resolve module LinkedStateMixin

    由于前面reactive文件夹的删除,导致运行程序的时候出现Unable to resolve module LinkedStateMixin 的错误. 搞了好久都没办法解决,看来不深入其中,无法解决 ...

  5. HDU2177:取(2堆)石子游戏(威佐夫博弈)

    Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同 ...

  6. Asp.Net Core- 多样性的配置来源

    我们知道,ConfigurationProvider提供将数据源转换为字典的功能,数据源可以分为很多种,比如:物理文件.数据库.内存变量等等.物理文件又包括很多种类型的文件,比如:xml.json等等 ...

  7. 【转】于request.getSession(true/false/null)的区别

    http://blog.csdn.net/gaolinwu/article/details/7285783 关于request.getSession(true/false/null)的区别 一.需求原 ...

  8. ios开发——实战OC篇&FMDB详解

    FMDB详解 前一篇文章中我们介绍的SQLite的使用,在iOS中原生的SQLite API在使用上相当不友好. 于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.Plausibl ...

  9. iOS开发——高级技术&摇一摇功能的实现

    摇一摇功能的实现 在AppStore中多样化功能越来越多的被使用了,所以今天就开始介绍一些iOS开发的比较实用,但是我们接触的比较少的功能,我们先从摇一摇功能开始 在 UIResponder中存在这么 ...

  10. Print2flash在.NET(C#)64位中的使用,即文档在线预览

    转:http://www.cnblogs.com/flowwind/p/3411106.html Print2flash在.NET(C#)中的使用,即文档在线预览   office文档(word,ex ...