IOS使用贝塞尔曲线画扇形

    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使用贝塞尔曲线画扇形)