zoukankan      html  css  js  c++  java
  • iOS之CAShapeLayer属性简介


    1、CAShapeLayer需要和贝塞尔曲线一块使用!

    #import <QuartzCore/CALayer.h>
    
    NS_ASSUME_NONNULL_BEGIN
    CA_CLASS_AVAILABLE (10.6, 3.0, 9.0, 2.0)
    @interface CAShapeLayer : CALayer
    
    //CGPathRef路径,不支持隐式动画
    @property(nullable) CGPathRef path;
    
    //填充颜色
    @property(nullable) CGColorRef fillColor;
    
    //填充规则(默认是非零法则) 齐偶原则
    @property(copy) NSString *fillRule;
    
    //路径颜色
    @property(nullable) CGColorRef strokeColor;
    
    //部分绘制[0-1],开始值和结束值
    @property CGFloat strokeStart;
    @property CGFloat strokeEnd;
    
    //先宽
    @property CGFloat lineWidth;
    
    //内角和外角距离
    @property CGFloat miterLimit;
    
    //线端口类型
    @property(copy) NSString *lineCap;
    
    //线连接处类型
    @property(copy) NSString *lineJoin;
    
    //绘制虚线路径
    //线型模板的起始位置
    @property CGFloat lineDashPhase;
    //线型模板 数组实线和虚线循环
    @property(nullable, copy) NSArray<NSNumber *> *lineDashPattern;
    
    @end
    
    /* `fillRule' values. */
    
    CA_EXTERN NSString *const kCAFillRuleNonZero    //非零
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
    CA_EXTERN NSString *const kCAFillRuleEvenOdd    //齐偶
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
    
    /* `lineJoin' values. */
    
    CA_EXTERN NSString *const kCALineJoinMiter
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
    CA_EXTERN NSString *const kCALineJoinRound
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
    CA_EXTERN NSString *const kCALineJoinBevel
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
    
    /* `lineCap' values. */
    
    CA_EXTERN NSString *const kCALineCapButt
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
    CA_EXTERN NSString *const kCALineCapRound
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
    CA_EXTERN NSString *const kCALineCapSquare
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
    
    NS_ASSUME_NONNULL_END

    2、简单使用

    - (void)starShowCAShapeLayer{
        UIBezierPath *bezi = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 100, 100)];
        CAShapeLayer *layer = [[CAShapeLayer alloc] init];
        layer.path = bezi.CGPath;
        layer.strokeColor = [UIColor redColor].CGColor;
        layer.fillColor = [UIColor whiteColor].CGColor;
        layer.lineWidth = 15;
        layer.strokeStart = 0;
        layer.strokeEnd = 0;
        layer.lineDashPattern = @[@4,@4];
        [self.showView.layer addSublayer:layer];
        self.layer = layer;
        
        self.waterTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(waterAction) userInfo:nil repeats:YES];
    }
    - (void)waterAction{
        if (self.layer.strokeEnd >=1) {
            [self.waterTimer invalidate];
            self.waterTimer = nil;
            return;
        }else{
            self.layer.strokeEnd +=0.02;
        }
    }

    效果图

  • 相关阅读:
    eclipse开发安卓 发短信打电话发送邮件功能
    关于springboot连接数据库是报错
    --Angular-01-关于angular-tree-component--
    --外功篇-Less的学习日志-01-辅助理解Less--
    --兵器谱--git学习记录帖--
    --兵器谱--git初体验--
    --算法恩仇录--实战篇--力扣(LeetCode)--022-括号生成--
    --算法恩仇录--实战篇--力扣(LeetCode)--011-盛水最多的容器--
    --算法恩仇录--实战篇--力扣(LeetCode)--006-Z字形变换--
    --算法恩仇录--实战篇--力扣(LeetCode)--005-最长回文子串--
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/7743627.html
Copyright © 2011-2022 走看看