美文网首页
IOS使用贝塞尔曲线画扇形

IOS使用贝塞尔曲线画扇形

作者: zhengxiaolang | 来源:发表于2018-08-28 13:27 被阅读0次
        UIBezierPath *bezierPath = [UIBezierPath bezierPath];
        //画圆弧 逆时针半圈
        [bezierPath addArcWithCenter:self.center radius:50 startAngle:0 endAngle:-M_PI clockwise:NO];
        [bezierPath setLineWidth:2];
        
        //画圆弧 顺时针半圈
        [bezierPath addArcWithCenter:CGPointMake(self.centerX - 100, self.centerY) radius:50 startAngle:0 endAngle:M_PI clockwise:YES];
        
        //如果没有闭合,只会显示弧线。
        [bezierPath addLineToPoint:CGPointMake(self.centerX + 50, self.centerY)];
        [bezierPath closePath];
        //  设置颜色(颜色设置也可以放在最上面,只要在绘制前都可以)
        [color196FFA setStroke];
        [colorClear setFill];
        // 描边和填充
        [bezierPath stroke];
        [bezierPath fill];
        
        CAShapeLayer *layer = [CAShapeLayer layer];
        layer.path = bezierPath.CGPath;
        layer.strokeColor = color196FFA.CGColor;
        layer.fillColor = colorClear.CGColor;
        layer.backgroundColor = colorClear.CGColor;
        
        CABasicAnimation *strokeEndAni = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        strokeEndAni.fromValue = @0;
        strokeEndAni.toValue = @(1);
        strokeEndAni.duration = 10.0f;
        strokeEndAni.repeatCount = 10; // 重复次数
        [layer addAnimation:strokeEndAni forKey:@"ani"];
        
        [self.layer addSublayer:layer];
        
        CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        pathAnimation.removedOnCompletion = NO;
        pathAnimation.duration = 10;//完成动画的时间
        //让循环连续演示
        pathAnimation.repeatCount = 10;
        pathAnimation.path = bezierPath.CGPath;
        UIImageView *circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_logo"]];
        circleView.frame = CGRectMake(1, 1, 40, 40);
        [self.view addSubview:circleView];
        
        //添加动画circleView——一旦你添加动画层,动画开始
        [circleView.layer addAnimation:pathAnimation
                                forKey:@"movecycle"];
    

    相关文章

      网友评论

          本文标题:IOS使用贝塞尔曲线画扇形

          本文链接:https://www.haomeiwen.com/subject/bhifwftx.html