一. 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基础控件 - 4.6] iOS开发中的长度单位

    对于开发中设置的位置.尺寸单位 系统会根据屏幕的性质转换为像素单位 由于视网膜屏在同样尺寸下分辨率是非视网膜屏的两倍,所以 非视网膜屏:1个单位 = 1像素 视网膜屏:1个单位 = 2像素   应对非 ...

  2. 有return的情况下try catch finally的执行顺序(最有说服力的总结)

    结论:1.不管有木有出现异常,finally块中代码都会执行:2.当try和catch中有return时,finally仍然会执行:3.finally是在return后面的表达式运算后执行的(此时并没 ...

  3. Win7 U盘安装Ubuntu16.04 双系统

    Win7系统下安装Ubuntu系统,主要分为三步: 第1步:制作U盘启动盘 第2步:安装Ubuntu系统 第3步:创建启动系统引导 第1步:制作U盘启动盘 1.下载Ubuntu16.04安装镜像,官网 ...

  4. Java循环语句 while

    特点:先判断,后执行 如: public class HelloWorld { public static void main(String[] args) { int i = 1; // 代表 1 ...

  5. EF如何正确的进行实体中修改

    本文转载:http://www.cnblogs.com/Ruiky/archive/2012/12/29/2839011.html 不推荐方式一: 思路:先从ObjectContext取出实体,然后将 ...

  6. mysqldump when doing LOCK TABLES问题

    今天打出表结构和数据遇到问题. mysqldump -udbuser -p dbname > dbname.sql 保存信息为: when doing LOCK TABLES 解决方法: mys ...

  7. dojo(四):ajax请求

    储备知识 1.在介绍新版本的ajax请求之前,需要先了解一些dojo/Deferreds. 初次听到“Deferred”这个概念,可能会觉得这是一个神秘的东西.实际上它在执行异步操作的时候非常强大,例 ...

  8. 用csc命令行手动编译cs文件

    一般初学c#时,用记事本写代码,然后用命令行执行csc命令行可以编译cs文件.方法有两种 1:配置环境,一劳永逸 一般来说在C:\Windows\Microsoft.NET\Framework\v4. ...

  9. 一个仿 github for windows 及 windows 8 的进度条

    https://github.com/wly2014/ProgressBar

  10. Qualcomm Web Site For Android Development

    https://www.codeaurora.org/xwiki/bin/QAEP/release https://support.cdmatech.com/login/ https://chipco ...