iOS核心动画CoreAnimation系统进阶(转场动画&组动画)
程序员文章站
2022-04-11 13:19:36
...
CATransition
核心代码
//转场动画:默认淡入淡出
CATransition *anim =[CATransition animation];
anim.type aaa@qq.com"suckEffect";//从父视图的左上角收缩
anim.startProgress =.5;//从动画进程的一半开始
anim.startProgress =.8;//从动画进程的百分之八十结束
[_imgView.layer addAnimation:anim forKey:nil];
动画组
在不使用动画组的情况下
//绘制贝塞尔曲线
UIBezierPath *path =[UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(50, 500)];
[path addCurveToPoint:CGPointMake(350, 500) controlPoint1:CGPointMake(170, 400) controlPoint2:CGPointMake(220, 300) ];
//添加到layer
CAShapeLayer * shapeLayer =[CAShapeLayer layer];
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = nil;
shapeLayer.strokeColor =[UIColor orangeColor].CGColor;
[self.view.layer addSublayer:shapeLayer];
//添加灰色方块
CALayer * colorLayer =[CALayer layer];
colorLayer.frame = CGRectMake(0, 0, 30, 30);
colorLayer.position = CGPointMake(50, 500);
colorLayer.backgroundColor =[UIColor grayColor].CGColor;
[self.view.layer addSublayer:colorLayer];
//添加关键帧动画
CAKeyframeAnimation * anim=[CAKeyframeAnimation animation];
anim.path = path.CGPath;
anim.keyPath aaa@qq.com"position";
anim.duration = 3;
[colorLayer addAnimation:anim forKey:nil];
//添加基础动画-动态改变颜色
CGFloat red =arc4random() /(CGFloat)INT_MAX;
CGFloat green =arc4random() /(CGFloat)INT_MAX;
CGFloat blue =arc4random() /(CGFloat)INT_MAX;
CABasicAnimation * basicAnim =[CABasicAnimation animation];
UIColor * color =[UIColor colorWithRed:red green:green blue:blue alpha:1];
basicAnim.keyPath aaa@qq.com"backgroundColor";
basicAnim.toValue = (id)color.CGColor;
basicAnim.duration = 3;
[colorLayer addAnimation:basicAnim forKey:nil];
//改变大小
CABasicAnimation * anim1 =[CABasicAnimation animation];
anim1.keyPath = @"transform.scale";
anim1.toValue aaa@qq.com.2;
anim1.duration = 3;
[colorLayer addAnimation:anim1 forKey:nil];
使用动画组
CAAnimationGroup * group =[CAAnimationGroup animation];
group.animations = @[anim1,anim,basicAnim];
group.duration = 3;
[colorLayer addAnimation:group forKey:nil];
优点是我们没必要写一些重复的属性.
效果图
推荐阅读
-
详解iOS开发中的转场动画和组动画以及UIView封装动画
-
IOS开发教程第一季之UI进阶day8合并IOS学习019--敲击、长按、轻扫、旋转,CALayer、锚点,CADisolayLink刷新,核心动画,关键帧动画,组动画,转场动画,画板案例
-
详解iOS开发中的转场动画和组动画以及UIView封装动画
-
iOS出门必备之CoreAnimation(核心动画)
-
iOS核心动画CoreAnimation系统进阶(转场动画&组动画)
-
iOS核心动画CoreAnimation系统进阶(自定义转场动画)
-
iOS核心动画CoreAnimation系统进阶(点赞经典动画 CAEmitterLayer 粒子动画详解)
-
iOS核心动画CoreAnimation系统进阶(仿QQ气泡拖拽效果)
-
iOS核心动画CoreAnimation系统进阶(2D物理引擎)
-
iOS核心动画CoreAnimation系统进阶(赛贝尔曲线-菜单侧滑动画拆分动画详解)