iOS Core Animation学习总结(3)--动画的基本类型
一. 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)--动画的基本类型的更多相关文章
- iOS Core Animation学习总结(1)--CALayer常用属性
图层是core animation的基础, UIView之所以能显示在屏幕上,靠的是其内部的这个图层,即每个UIView 都有 CALayer,可通过UIView.layer或者[UIView lay ...
- iOS Core Animation学习总结(2)--实现自定义图层
一. 创建图层继承于CALayer,并在子类实现drawInContext方法 @interface CTLayer : CALayer @end @implementation CTLayer -( ...
- 转 iOS Core Animation 动画 入门学习(一)基础
iOS Core Animation 动画 入门学习(一)基础 reference:https://developer.apple.com/library/ios/documentation/Coco ...
- iOS - Core Animation 核心动画
1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...
- Core Animation学习总结
文件夹: The Layer Beneath The Layer Tree(图层树) The Backing Image(寄宿层) Layer Geometry(图层几何学) Visual Effec ...
- iOS Core Animation 简明系列教程
iOS Core Animation 简明系列教程 看到无数的CA教程,都非常的难懂,各种事务各种图层关系看的人头大.自己就想用通俗的语言翻译给大家听,尽可能准确表达,如果哪里有问题,请您指出我会尽 ...
- 使用Core Animation对象来实现动画
转载保留原文地址:http://blog.csdn.net/kqjob/article/details/10417461,转载的 在iOS中如果使用普通的动画则可以使用UIKit提供的动画方式来实现, ...
- iOS Core Animation 动画 入门学习(一)基础
reference:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide ...
- IOS Core Animation Advanced Techniques的学习笔记(五)
第六章:Specialized Layers 类别 用途 CAEmitterLayer 用于实现基于Core Animation粒子发射系统.发射器层对象控制粒子的生成和起源 CAGradient ...
随机推荐
- weblogic11g 安装——linux 无图形界面
weblogic11g 安装——linux下无weblogic安装图形界面 注意:此次安装,没做server.ip .系统规划 目的:学习weblogic11g 在linux下 无图形安装的过程 j ...
- angular-tour 用户新手引导
下载安装 bower install angular-tour 建立依赖,引入文件 <script src="bower_components/jquery/jquery.js&quo ...
- Ognl表达式语言
l OGNL表达式 OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目. Struts2框架使用OGNL作为默认的表达式语言. ...
- hbase运维
NoSQL现在风生水起,hbase的使用也越来越广,但目前几乎所有的NoSQL产品在运维上都没法和DB相提并论,在这篇blog中来总结下我们在运维hbase时的一些问题以及解决的方法,也希望得到更多h ...
- 秀一套每秒处理1500+个事务的profile
秀一套每秒处理1500+个事务的profile,真实生产环境
- 【Cocos2d-X开发学习笔记】第09期:渲染框架之菜单类(CCMenu)的使用
本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 一.菜单项(CCMenuItem) 菜单项 ...
- DBHelper数据库操作类(二)
不错文章:http://www.codefans.net/articles/562.shtml http://www.cnblogs.com/gaobing/p/3878342.html using ...
- EF如何正确的进行实体中修改
本文转载:http://www.cnblogs.com/Ruiky/archive/2012/12/29/2839011.html 不推荐方式一: 思路:先从ObjectContext取出实体,然后将 ...
- jquery回车提交表单
jquery回车提交表单,比较方便的功能. 三个事件keydown,keypress,keyup,分别是按下,按着没上抬,上抬键盘 ,所以用keyup. $(document).keyup(funct ...
- Effective C++ 第二版 17)operator=检查自己 18)接口完整 19)成员和友元函数
条款17 在operator=中检查给自己赋值的情况 1 2 3 class X { ... }; X a; a = a; // a 赋值给自己 >赋值给自己make no sense, 但 ...