动画

隐式动画

        //开始动画事务
        [CATransaction begin];
        //动画执行时间
        [CATransaction setAnimationDuration:5];
        //设置动画代码块
        layer.backgroundColor = [UIColor greenColor].CGColor;
        //动画完成时机
        [CATransaction setCompletionBlock:^{
            NSLog(@"动画完成");
        }];
        //提交动画事务,begin和commit之间改变的CALayer属性,如果为Animatable,就会执行动画
        [CATransaction commit];

CABaseAnimation

        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        //动画执行时间
        animation.duration = 1;
        //执行时间
        animation.fromValue = @0;
        //目标值
        animation.toValue = @1;
        //动画时间的消耗曲线
        //1.慢-快-慢
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        //2.默认为匀速
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
        //贝兹曲线
        animation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:.25 :.1 :.25 :.1];
        [shaperLayer addAnimation:animation forKey:@"animation"];

坐标绘制

绘制工具: Paint Code

    CAShapeLayer *shaperLayer = [CAShapeLayer layer];
    shaperLayer.strokeColor = [UIColor redColor].CGColor;
    shaperLayer.frame = self.view.frame;
    shaperLayer.fillColor = [UIColor clearColor].CGColor;
    shaperLayer.lineWidth = 10;
    [self.view.layer addSublayer:shaperLayer];
    
    //// Star Drawing
    UIBezierPath* starPath = UIBezierPath.bezierPath;
    [starPath moveToPoint: CGPointMake(203, 122)];
    [starPath addLineToPoint: CGPointMake(234.74, 173.72)];
    [starPath addLineToPoint: CGPointMake(288.6, 191.44)];
    [starPath addLineToPoint: CGPointMake(254.36, 241.13)];
    [starPath addLineToPoint: CGPointMake(255.9, 303.81)];
    [starPath addLineToPoint: CGPointMake(203, 282.8)];
    [starPath addLineToPoint: CGPointMake(150.1, 303.81)];
    [starPath addLineToPoint: CGPointMake(151.64, 241.13)];
    [starPath addLineToPoint: CGPointMake(117.4, 191.44)];
    [starPath addLineToPoint: CGPointMake(171.26, 173.72)];
    [starPath closePath];
    
    shaperLayer.path = starPath.CGPath;

CAKeyFrameAnimation

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
    //动画执行时间
    animation.duration = 5;
    id color1 = (__bridge id)[UIColor redColor].CGColor;
    id color2 = (__bridge id)[UIColor greenColor].CGColor;
    id color3 = (__bridge id)[UIColor blueColor].CGColor;
    //关键帧的值
    animation.values = @[color1,color2,color3];
    //关键帧出现的时刻
    animation.keyTimes = @[@0.2,@0.6,@0.8];
    [layer addAnimation:animation forKey:@""];
    CALayer *demoLayer = [CALayer layer];
    demoLayer.backgroundColor = [UIColor redColor].CGColor;
    demoLayer.frame = CGRectMake(100, 100, 30, 30);
    [self.view.layer addSublayer:demoLayer];

    
    CAShapeLayer *shaperLayer = [CAShapeLayer layer];
    shaperLayer.strokeColor = [UIColor greenColor].CGColor;
    shaperLayer.frame = self.view.frame;
    shaperLayer.fillColor = [UIColor clearColor].CGColor;
    shaperLayer.lineWidth = 4;
    [self.view.layer addSublayer:shaperLayer];
    
    CAKeyframeAnimation *aniamtion = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    aniamtion.duration = 5;
    
    //// Bezier Drawing
    UIBezierPath* bezierPath = UIBezierPath.bezierPath;
    [bezierPath moveToPoint: CGPointMake(59.5, 82.5)];
    [bezierPath addCurveToPoint: CGPointMake(320.5, 119.5) controlPoint1: CGPointMake(59.5, 82.5) controlPoint2: CGPointMake(303.5, -47.5)];
    [bezierPath addCurveToPoint: CGPointMake(45.5, 675.5) controlPoint1: CGPointMake(337.5, 286.5) controlPoint2: CGPointMake(-27.5, 543.5)];
    [bezierPath addCurveToPoint: CGPointMake(267.5, 646.5) controlPoint1: CGPointMake(118.5, 807.5) controlPoint2: CGPointMake(209.5, 754.5)];
    shaperLayer.path = bezierPath.CGPath;
    
    //设置动画的路径
    aniamtion.path = bezierPath.CGPath;
    //让图像的头部随着动画变化而变化
    aniamtion.rotationMode = kCAAnimationRotateAuto;
    //设置动画自动回到回复为YES,且完成之后回到原点
    aniamtion.autoreverses = YES;
    //动画执行次数为2次
    aniamtion.repeatCount = 2;
    //表现层停留在动画完成状态
    aniamtion.fillMode = kCAFillModeForwards;
    //动画完成后不移除,一直处于最后状态
    aniamtion.removedOnCompletion = NO;
    
    [demoLayer addAnimation:aniamtion forKey:@""];

CAAnimationGroup

CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[animation, animation1];
group.duration = 10;
[_animationLayer addAnimation:group forKey:@"group"];

切换动画CATransition(酷炫效果,网上搜索)

CATransition *transition = [CATransition animation];
//动画类型
 transition.type = kCATransitionReveal;
// 子类型
transition.subtype = kCATransitionFromBottom;
transition.duration = 10;
[_animationLayer addAnimation:transition forKey:@"xx"];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 显式动画 显式动画,它能够对一些属性做指定的自定义动画,或者创建非线性动画,比如沿着任意一条曲线移动。 属性动画 ...
    清风沐沐阅读 6,141评论 1 5
  • 显式动画 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念。隐式动画是iOS平台上...
    方圆几度阅读 3,567评论 0 0
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 8,403评论 1 23
  • 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念。隐式动画是在iOS平台创建动态用...
    雪_晟阅读 3,638评论 0 1
  • 《理想国》可能是一本假书,书的前两章对财产,对理想政治的讨论,语言简单,思想涵度不高,可能,这和名牌效应一样吧。在...
    钟独阅读 2,600评论 3 3

友情链接更多精彩内容