美文网首页
绘制动画,核心动画

绘制动画,核心动画

作者: 阿么阿么 | 来源:发表于2016-04-28 22:24 被阅读0次

暂记......


一、Core Animation简介

(1)Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果

(2)Core Animation的动画执行过程都是在后台操作的,不会阻塞主线程。

(3)Core Animation是直接作用在CALayer上的,并非UIView。

二、Core Animation的使用步骤

1.使用它需要先添加QuartzCore.framework框架和引入主头文件

2.初始化一个CAAnimation对象,并设置一些动画相关属性

3.通过调用CALayer的addAnimation:forKey:方法增加CAAnimation对象到CALayer中,这样就能开始执行动画了

4.通过调用CALayer的removeAnimationForKey:方法可以停止CALayer中的动画

1.过渡动画(转场动画)

CATransition

(1)视图切换

(2)控制器切换

2.关键帧动画

CAKeyframeAnimation

(1)values

(2)path

(3)输入框输入错误动画

(4)视图抖动效果

(5)点赞动画

calculationMode是控制关键帧动画时间的另一种方法。我们通过将其设置为kCAAnimationPaced,让Core Animation向被驱动的对象施加一个恒定速度,不管路径的各个线段有多长。

additive属性为YES能够对所有形式的需要更新的元素重用相同的动画,且无需提前知道它们的位置。

3.基本动画

CABasicAnimation

(1)旋转

(2)摇一摇

byValue和toValue的区别,前者是在当前的位置上增加多少,后者是到指定的位置。

4.CAAnimationGroup动画组

使用函数CGContextAddCurveToPoint去 使用一个三次Bezier 曲线,要我们指定control point和endpoint。下图是一个三次的Bezier曲线,有两个控制点。两个控制点的定义了曲线的几何形状。如果两个控制点都在起点和终点的下 面,则则曲线向上供。如果第二个控制点相比第一个控制点更接近起点,则曲线会构成一个循环。

使用函数CGContextAddQuadCurveToPoint 去使用添加一个二次Bezier曲线,要我们指定一个control point和endpoint。下图展示了相同的endpoint,不同的control point的结果。control point定义了曲线的供的方向。利用二次Bezier曲线不可能创造用三次Bezier曲线那么多的有趣的曲线。例如,用二次不可能创造一个交叉的曲 线。

-(void)addProductsAnimationWithImageView:(UIImageView*)imageView

{

//将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect

//把UITableViewCell中的subview(btn)的frame转换到self.view中

CGRectmyFrame = [imageViewconvertRect:imageView.boundstoView:self.view];

//CGFloat Ix = myFrame.origin.x;

//CGFloat Iy = myFrame.origin.y;

//[self.view addSubview:self.imgView];

//self.imgView.frame = CGRectMake(Ix , Iy , 25, 25);

CALayer*layer1 = [[CALayeralloc]init];

layer1.frame= myFrame;

//layer1.frame = self.imgView.frame;

//layer1.contents = self.imgView.layer.contents;

layer1.contents= imageView.layer.contents;

[self.view.layeraddSublayer:layer1];

[self.myLayersArraddObject:layer1];

//*********

// **图片初始的位置

CGPointbeginPoint = layer1.position;

// **购物车左上角圆圆的红点位置

CGPointendPoint =CGPointMake(SCREENWIDTH-SCREENWIDTH/4-SCREENWIDTH/8-6,SCREENHEIGHT-40);

// 2.创建一个CGMutablePathRef的可变路径,并返回其句柄

CGMutablePathRefpath =CGPathCreateMutable();

CGPathMoveToPoint(path,nil, beginPoint.x, beginPoint.y);

CGPathAddCurveToPoint(path,nil, beginPoint.x, beginPoint.y-30, endPoint.x, beginPoint.y-30, endPoint.x, endPoint.y);

//1.创建核心动画

CAKeyframeAnimation*positionAnimation = [CAKeyframeAnimationanimation];

positionAnimation.keyPath=@"position";

positionAnimation.path= path;

//*********

CABasicAnimation*opacityAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];

opacityAnimation.fromValue= [NSNumbernumberWithFloat:1];

opacityAnimation.toValue= [NSNumbernumberWithFloat:0.9];

opacityAnimation.fillMode=kCAFillModeForwards;

opacityAnimation.removedOnCompletion=YES;

//*********

CABasicAnimation*transformAnimation = [CABasicAnimationanimationWithKeyPath:@"transform"];

transformAnimation.fromValue= [NSValuevalueWithCATransform3D:CATransform3DIdentity];

transformAnimation.toValue= [NSValuevalueWithCATransform3D:CATransform3DScale(CATransform3DIdentity,0.2,0.2,1)];

//*********

CAAnimationGroup*groupAnimation = [CAAnimationGroupanimation];

//groupAnimation.animations = @[positionAnimation, transformAnimation, opacityAnimation];

groupAnimation.animations= [NSArrayarrayWithObjects:positionAnimation, transformAnimation, opacityAnimation,nil];

groupAnimation.duration=0.8;

groupAnimation.delegate=self;

//**********

[layer1addAnimation:groupAnimationforKey:@"cartParabola"];

//[self.view.layer addAnimation:groupAnimation forKey:nil];

}

#pragma mark -重写方法

-(void)animationDidStop:(CAAnimation*)anim finished:(BOOL)flag

{

if(self.myLayersArr.count>0) {

CALayer*tempLayer =self.myLayersArr[0];

tempLayer.hidden=YES;

self.imgView.hidden=YES;

[tempLayerremoveFromSuperlayer];

[self.myLayersArrremoveAllObjects];

[self.view.layerremoveAnimationForKey:@"cartParabola"];

}

}

#pragma mark - setter and getter

-(NSMutableArray*)myLayersArr

{

if(!_myLayersArr) {

_myLayersArr= [NSMutableArrayarray];

}

return_myLayersArr;

}

-(UIImageView*)imgView

{

if(!_imgView) {

_imgView= [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"v2_test_entry_icon"]];

}

return_imgView;

}

相关文章

  • iOS 17:项目实战:彩票

    项目:彩票 核心动画,常用核心动画绘制。 模拟器和真机的尺寸,跟启动画面有关。 launchScreen 底层实现...

  • iOS 贝塞尔曲线路径动画 SVG快速实现(Swift版)

    本文将简单实现iOS快速路径绘制动画。 什么核心动画(Core Animation)、CAShapeLayer、U...

  • 绘制动画,核心动画

    暂记...... 一、Core Animation简介 (1)CoreAnimation,中文翻译为核心动画,它是...

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

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

  • 快速上手核心动画

    1、什么是核心动画 Core Animation是一套包含图形绘制、投影、动画的Objective-C类集合,该框...

  • IOS 核心动画CoreAniamation总结

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

  • iOS-核心动画

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

  • iOS动画(Core Animation)

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

  • iOS动画

    序列帧动画渐变动画基本动画核心动画

  • iOS面试个人总结(1)

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

网友评论

      本文标题:绘制动画,核心动画

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