UIBezierPath 画勾,圆

//bgView 是一个UIView,我将它作为底图
//以bgView 为基准选定位置
    CGPoint pathCenter = CGPointMake(bgView.frame.size.width/2, bgView.frame.size.height/2 - 50);
//画出一个圆(起始为0,画360°,半径为40)
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:pathCenter radius:40 startAngle:0 endAngle:M_PI *2  clockwise:YES];
    
    path.lineCapStyle  = kCGLineCapRound; // 线条拐角
    path.lineJoinStyle = kCGLineCapRound; // 线条终点处理
    
    //画勾(起点,最低点,最高点)并将画的线添加上去
    CGFloat x = bgView.frame.size.width/2.5 + 5;
    CGFloat y = bgView.frame.size.height/2 - 45;
    [path moveToPoint:CGPointMake(x, y)];
    [path addLineToPoint:CGPointMake(x + 10, y + 30)];
    [path addLineToPoint:CGPointMake(x + 50, y - 30)];
    
    CAShapeLayer *layer = [[CAShapeLayer alloc] init];
    //图层中线条的颜色
    layer.strokeColor = [[UIColor redColor] CGColor];
    layer.path = path.CGPath;
    //图层未画图部分填充色,默认是黑色
    layer.fillColor = [UIColor clearColor].CGColor;
    //图层中线条宽度
    layer.lineWidth = 5;
    //添加动画,图层上的线条呈现画的效果
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:NSStringFromSelector(@selector(strokeStart))];
    animation.fromValue = @0;
    animation.toValue = @1;
    animation.duration = 0.5;
    [layer addAnimation:animation forKey:NSStringFromSelector(@selector(strokeStart))];
    [bgView.layer addSublayer:layer];

转载于:https://my.oschina.net/u/2507274/blog/598593

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值