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

效果图

 

转载于:https://www.cnblogs.com/xianfeng-zhang/p/7743627.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值