【问题标题】:CAShapeLayer Animation color issueCAShapeLayer 动画颜色问题
【发布时间】:2014-09-02 18:12:06
【问题描述】:

我正在使用以下代码来绘制图表:

- (void) drawCircleGraphWithPercentage:(CGFloat)percentage
{


    self.circle = [[CAShapeLayer alloc] init];
    self.circle.strokeColor = [UIColor whiteColor].CGColor;
    self.circle.backgroundColor = [AESColorUtilities mdvdYellow].CGColor;

    self.circle.lineWidth = 30.0;

    // Make a circular shape
    self.circle.path = self.circlePath.CGPath;


    // Add to parent layer
    [self.contentView.layer addSublayer:self.circle];
    [self.contentView bringSubviewToFront:self.percentageLabel];

    // Configure animation
    CABasicAnimation* drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    drawAnimation.duration            = 1.0; // "animate over 10 seconds or so.."
    drawAnimation.repeatCount         = 1.0;  // Animate only once..

    // Animate from no part of the stroke being drawn to the entire stroke being drawn
    drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    drawAnimation.toValue   = [NSNumber numberWithFloat:1.0f];

    // Experiment with timing to get the appearence to look the way you want
    drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    // Add the animation to the circle
    [self.circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
}

我遇到的问题是图层中有黑色形状导致颜色关闭:

我怎样才能使背景全是黄色的“mdvdYellow”而没有后面的黑色?

提前谢谢你。

【问题讨论】:

    标签: ios objective-c calayer cashapelayer


    【解决方案1】:

    您需要从形状图层中删除fillColor,因为默认为不透明黑色。

    fillColor 设置为nil 会导致不渲染填充。

    self.circle.fillColor = nil;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      相关资源
      最近更新 更多