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;
        }
    }

    效果图

  • 相关阅读:
    【Python开发】python使用urllib2抓取防爬取链接
    【Python开发】python使用urllib2抓取防爬取链接
    【Python开发】Python之re模块 —— 正则表达式操作
    【Python开发】Python之re模块 —— 正则表达式操作
    【Python开发】Url中文字符时记得转码edcode("utf-8")
    【Python开发】Url中文字符时记得转码edcode("utf-8")
    【Python开发】urllib2异常处理
    【Python开发】urllib2异常处理
    【Python开发】urllib2.urlopen超时问题
    【Python开发】urllib2.urlopen超时问题
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/7743627.html
Copyright © 2011-2022 走看看