ios-核心动画
2017-08-02 17:07
78 查看
核心动画其实就是Core Animation可以用在Mac OS X 和iOS的平台
Core Animation 的动画执行过程都是在后台进行操作的,不会堵塞主线程。
Core Animation是直接作用在CALayer上,不是作用在UIView上。
核心动画可以修改动画执行的时间
核心动画结束后会回到原来的位置
1、基本动画(CABasicAnimation)
KeyPath 需要修改的属性
fromValue 从哪里
toValue 到哪里
byValue 累加到那
repeatCount 重复次数
duration 是动画执行的时间
2、关键帧动画(CAKeyframeAnimation)
keyPath 需要修改的属性
values 放关键帧的数组
path 做动画的路径
3、组动画(CAAnimationGroup)
animations 放各种动画的数组
如果我们要设置动画的执行时间和重复的次数,就是要给这个组动画进行设置的
4、转场动画(CATransition)
type 动画类型
subtype 方向
基本动画是属性动画的一种
Core Animation 的动画执行过程都是在后台进行操作的,不会堵塞主线程。
Core Animation是直接作用在CALayer上,不是作用在UIView上。
核心动画可以修改动画执行的时间
核心动画结束后会回到原来的位置
1、基本动画(CABasicAnimation)
KeyPath 需要修改的属性
fromValue 从哪里
toValue 到哪里
byValue 累加到那
repeatCount 重复次数
duration 是动画执行的时间
2、关键帧动画(CAKeyframeAnimation)
keyPath 需要修改的属性
values 放关键帧的数组
path 做动画的路径
3、组动画(CAAnimationGroup)
animations 放各种动画的数组
如果我们要设置动画的执行时间和重复的次数,就是要给这个组动画进行设置的
4、转场动画(CATransition)
type 动画类型
subtype 方向
基本动画是属性动画的一种
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { //基本动画类型 //1、创建动画的对象也就是你需要做什么动画 CABasicAnimation * animation=[[CABasicAnimation alloc]init]; //2、怎么去做动画 //x从15到200 animation.keyPath=@"position.x"; // animation.fromValue=@(15); // animation.toValue=@(200); //禁止返回到原来的位置就是从自身的位置去累加x animation.byValue=@(5); //动画完成不回到原来的位置 animation.fillMode=kCAFillModeForwards; animation.removedOnCompletion=NO;//不设置这个,上面的那个就没有效果 //添加动画,就是设置对谁去做动画 [self.layer addAnimation:animation forKey:nil]; }关键帧动画也是属性动画的一种
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { //创建动画 CAKeyframeAnimation *animation =[[CAKeyframeAnimation alloc]init]; animation.keyPath=@"position"; // NSValue * v1=[NSValue valueWithCGPoint:CGPointMake(100, 100)]; // NSValue * v2=[NSValue valueWithCGPoint:CGPointMake(150, 100)]; // NSValue * v3=[NSValue valueWithCGPoint:CGPointMake(100, 150)]; // NSValue * v4=[NSValue valueWithCGPoint:CGPointMake(150, 150)]; // //四个关键数据 // animation.values=@[v1,v2,v3,v4]; //动画执行的时间 animation.duration=5; //重复次数 animation.repeatCount=INT_MAX; //还有就是创建个路径,让layer绕着这个路径走 UIBezierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI clockwise:YES]; animation.path=path.CGPath; //添加动画 [self.layer addAnimation:animation forKey:nil]; }组动画中包含基本动画和关键帧动画
//创建组动画 CAAnimationGroup * group=[[CAAnimationGroup alloc]init]; //创建基本动画 CABasicAnimation * animation=[[CABasicAnimation alloc]init]; animation.keyPath=@"transform.rotation"; //让方块自己自旋转 animation.byValue=@(2*M_PI); //创建关键帧动画 CAKeyframeAnimation * animation1 =[[CAKeyframeAnimation alloc]init]; //怎么做动画 animation1.keyPath=@"position"; //创建路径 UIBez 4000 ierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI clockwise:YES]; //设置关键帧动画的路径 animation1.path=path.CGPath; //设置组动画中的动画 group.animations=@[animation,animation1]; //设置动画的执行时间 group.duration=2; //重复次数 group.repeatCount=INT_MAX; //添加动画 [self.layer addAnimation:group forKey:nil];转场动画,其中self.imageNumber只是为了更好的去设置图片而去定义的
- (IBAction)imageChange:(UISwipeGestureRecognizer *)sender { //创建动画 CATransition * animation=[[CATransition alloc]init]; //进行设置 animation.type=@"cube"; //rippleEffect是水滴效果没有方向,cameraIrisHollowOpen是相机效果没有方向区别,moveIn就是换张图片上一张图片变透明的效果 //设置方向 animation.subtype=kCATransitionFromLeft; if(sender.direction==UISwipeGestureRecognizerDirectionLeft) { self.imageNumber++; if(self.imageNumber==8) { self.imageNumber=1; } self.imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%ld",self.imageNumber]]; //设置方向,从右往左 animation.subtype=kCATransitionFromRight; } else { self.imageNumber--; if(self.imageNumber==0) { self.imageNumber=7; } //设置方向 animation.subtype=kCATransitionFromLeft; self.imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%ld",self.imageNumber]]; } //添加动画效果 [self.imageView.layer addAnimation:animation forKey:nil]; }
相关文章推荐
- iOS记录App、封装播放器、核心动画、加载框架、分段器、多种控件等源码
- iOS开发UI篇—核心动画(关键帧动画)
- iOS动画-核心动画(Core Animation)
- iOS开发UI篇—核心动画简介
- iOS核心动画高级技巧
- iOS_核心动画CALayer(一)
- 011-iOS核心动画(Core Animation)
- iOS开发概述 - 16.CAAnimation(核心动画实例)
- iOS开发UI篇—核心动画(UIView封装动画)
- iOS核心动画 CALayer
- 十 iOS 之UIVIew动画 和 核心动画的区别
- iOS之CALayer核心动画详解
- iOS核心动画笔记6-专用图层
- iOS核心动画简介
- ios-day18-06(核心动画Core Animation简介、CAAnimation属性介绍)
- iOS学习笔记-核心动画
- IOS核心动画 - Core Animation
- 《iOS核心动画高级技巧》part1-CALayer
- iOS Objective-C基本核心动画,偏移,旋转,缩放,路径,抖动,组动画
- ios之核心动画(二)