美文网首页
核心动画

核心动画

作者: nothing_c | 来源:发表于2016-10-30 23:28 被阅读41次

//  CoreAnimationDemo

//    CATransaction事务动画(显示动画(开头和结尾)和隐式动画)

//    CAAnimation是一个基类定义一些动画的基本属性和方法

//    CAPropertyAnimation属相动画是一个抽象的子类,支持动画的显示图层的关键路径(KeyPath)中定制的属性

//    CABasicAnimation基础动画简单的为图层属性提供修改

//    CAAnimationGroup组动画

//    CAKeyframeAnimation关键帧动画

//    CATransition过渡动画

//动画结束不移除动画效果(不返回)

CAAnimation *caa = nil;

caa.removedOnCompletion = NO;

caa.fillMode = kCAFillModeForwards;

CABasicAnimation *base;

//在你原来的基础上继续动画

base.cumulative =YES;

//事务动画

- (void)doTranscationAnimation {

//事务分为显示和隐式

//隐式事务指的是我们不去控制它的发生过程,只关心结果的时候,系统默认帮我们添加的一个动画的过程

//显示事务指的是我们明确的控制动画的发生过程

//显示动画

//开始

[CATransaction begin];

//动画时间

[CATransaction setAnimationDuration:0.5];

//速率函数

[CATransactionsetAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

//动画(图层)动画体

if(_layer.cornerRadius >= 30) {

_layer.cornerRadius = 10;

_layer.backgroundColor = [UIColor orangeColor].CGColor;

}else{

_layer.cornerRadius = 50;

_layer.backgroundColor= [UIColor blueColor].CGColor;

}

//提交

[CATransaction commit];

}

/*

keyPath::::::::::

边框颜色:borderColor

旋转:transform.rotation.ztransform.rotation.z

缩放:transform.scale

位置:position

背景颜色:backgroundColor

*/

//基础动画

- (void)doBaseAnimation {

//    CABasicAnimation

//创建基础动画对象

CABasicAnimation *borederColorAnimation = [CABasicAnimation animation];

//设置关键路径(做什么动画)

borederColorAnimation.keyPath = @"borderColor";

//动画时间

borederColorAnimation.duration= 0.5f;

//动画的值

borederColorAnimation.byValue= (id)[UIColor blueColor].CGColor;

//是否自动重复

borederColorAnimation.autoreverses =YES;

//设置重复次数

borederColorAnimation.repeatCount= 5;

//把动画添加到动画对象上

//    [_layer addAnimation:borederColorAnimation forKey:@"borederColor_Animation"];

//旋转

CABasicAnimation *rotationAnimotion = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

rotationAnimotion.duration= 1.5;

rotationAnimotion.toValue= @(M_PI);

rotationAnimotion.autoreverses=YES;

//    [_layer addAnimation:rotationAnimotion forKey:@"rotation_Animotion"];

//缩放

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

scaleAnimation.duration= 1.5;

scaleAnimation.toValue= @(2.0);

scaleAnimation.autoreverses=YES;

//    [_layer addAnimation:scaleAnimation forKey:@"scale_Animation”];

//组动画

CAAnimationGroup *group = [CAAnimationGroup animation];

group.animations= @[borederColorAnimation,rotationAnimotion,scaleAnimation];

group.duration=3;

[_layer addAnimation:groupforKey:@"Group_Animaton"];

}

//关键帧动画

- (void)doKeyFrameAnimation {

CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

positionAnimation.duration= 2;

//动画过程的设置

//获得原始数据获取图层位置

CGPointpoint =_layer.position;

//设置过程

positionAnimation.values= @[[NSValuevalueWithCGPoint:point],[NSValuevalueWithCGPoint:CGPointMake(0, 400)],[NSValuevalueWithCGPoint:CGPointMake(300, 400)],[NSValuevalueWithCGPoint:point]];

//规定每个帧动画的时间从什么时候开始

positionAnimation.keyTimes= @[@0,@0.3,@0.5,@1];

//将动画添加个目标对象

[_layer addAnimation:position AnimationforKey:@"position_Animation"];

CAKeyframeAnimation *backgroundColorAnimation = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];

backgroundColorAnimation.duration= 2;

backgroundColorAnimation.values= @[(id)[UIColor redColor].CGColor,(id)[UIColor greenColor].CGColor,(id)[UIColor blueColor].CGColor];

[_layer addAnimation:backgroundColor AnimationforKey:@"backgroundColor_Animation"];

}

//过渡动画

- (void)doTransitionAnimation {

CATransition *transitionAnimation = [CATransition animation];

transitionAnimation.duration= 2;

//kCATransitionMoveIn

transitionAnimation.type=@"cube";

NSArray *subtypeArray = @[kCATransitionFromLeft,kCATransitionFromRight,kCATransitionFromBottom,kCATransitionFromTop,kCATransitionFromLeft];

transitionAnimation.subtype= subtypeArray[arc4random()%(subtypeArray.count)];

[_layer addAnimation:transition AnimationforKey:@"transition_Animation"];


/*

//transitionAnimation.type = @"oglFlip";

以下API效果可以安全使用

cube方块

suckEffect三角

rippleEffect水波抖动

pageCurl上翻页

pageUnCurl下翻页

oglFlip上下翻转

cameraIrisHollowOpen镜头快门开

cameraIrisHollowClose镜头快门开

以下API效果请慎用

spewEffect新版面在屏幕下方中间位置被释放出来覆盖旧版面.

genieEffect旧版面在屏幕左下方或右下方被吸走,显示出下面的新版面

unGenieEffect新版面在屏幕左下方或右下方被释放出来覆盖旧版面.

twist版面以水平方向像龙卷风式转出来.

tubey版面垂直附有弹性的转出来.

swirl旧版面360度旋转并淡出,显示出新版面.

charminUltra旧版面淡出并显示新版面.

zoomyIn新版面由小放大走到前面,旧版面放大由前面消失.

zoomyOut新版面屏幕外面缩放出现,旧版面缩小消失.

oglApplicationSuspend像按”home”按钮的效果.

*/

}


结构字段的键的取值

CAAnimation供支持使用关键路径访问选择的结构字段。这在为动画关键路径指定结构字段的时候非常有帮助,同时你可以使用setValue:forKeyPath:和valueForKeyPath来设置和读取相应的值。

CATransform3D公开如下的字段:

结构体字段                          描述

transform.rotation.x              The rotation, in radians, in the x axis.

transform.rotation.y              The rotation, in radians, in the y axis.

transform.rotation.z            The rotation, in radians, in the z axis.

transform.rotation                  The rotation, in radians, in the z axis. This is identical to setting the rotation.z field.

transform.scale.x                  Scale factor for the x axis.

transform.scale.y                  Scale factor for the y axis.

transform.scale.z                 Scale factor for the z axis.

transform.scale                   Average of all three scale factors.

transform.translation.x          Translate in the x axis.

transform.translation.y           Translate in the y axis.

translation.z                          Translate in the z axis.

translation                            Translate in the x and y axis. Value is an NSSize or CGSize.

CGPoint公开如下字段:

结构体字段描述

x                          The x component of the point.

y                           The y component of the point.

CGSize公开如下字段:

结构体字段描述

width                      The width component of the size.

height                     The height component of the size.

CGRect公开如下字段:

结构体字段描述

origin                      The origin of the rectangle as a CGPoint.

origin.x                    The x component of the rectangle origin.

origin.y                     The y component of the rectangle origin.

size                           The size of the rectangle as a CGSize.

size.width                  The width component of the rectangle size.

size.height                The height component of the rectangle size

你不可以通过Objective-C 2.0的属性方法来指定一个结构字段的关键路径。如下的代码是无法正常执行的:

myLayer.transform.rotation.x = 0;

相反你必须使用setValue:forKeyPath:或者valuForKeyPath:,如下:

[myLayer setValue:[NSNumber numberWithInt:0] forKeyPath:@"transform.rotation.x"];

相关文章

  • IOS 核心动画CoreAniamation总结

    iOS 核心动画是基于CALayer层的动画,UIView动画是系统对核心动画的封装,核心动画相对UIView来说...

  • iOS基础 - 核心动画(转)

    iOS基础 - 核心动画 一、核心动画 l核心动画基本概念 l基本动画 l关键帧动画 l动画组 l转场动画 lCo...

  • iOS核心动画高级技巧 - 8

    iOS核心动画高级技巧 - 1iOS核心动画高级技巧 - 2iOS核心动画高级技巧 - 3iOS核心动画高级技巧 ...

  • iOS动画(Core Animation)

    1.核心动画(Core Animation):强大的动画API 核心动画所在的位置如下图 核心动画位于UIKit的...

  • IOS 常用动画的实现方式整理

    一、CoreAnimation(核心动画) 1.核心动画介绍 1.什么是核心动画 Core Animation可以...

  • UIview动画和核心动画的区别

    UIView和核心动画的区别 核心动画只能添加到CALayer,UIView没有办法使用核心动画 核心动画一切都是...

  • iOS-核心动画

    前言:核心动画的基础知识,包括基本动画、帧动画、转场动画相关知识。 一、核心动画(Core Animation) ...

  • iOS面试个人总结(1)

    动画 1.UIView动画与核心动画的区别? 核心动画只作用在layer. 核心动画修改的值都是假像.它的真实位置...

  • 再来看看动画

    动画一般有:UIKit动画和CoreAnimation(核心)动画 下面主要是核心动画的内容:http://www...

  • 一头扎进iOS核心动画(一)

    记录一下学习的笔记 核心动画 核心动画基本概念 基本动画 关键帧动画 动画组 转场动画 Core Animatio...

网友评论

      本文标题:核心动画

      本文链接:https://www.haomeiwen.com/subject/rjiuuttx.html