2014-09-02 93 views
0

我使用以下代碼來繪製的曲線圖:CAShapeLayer動畫彩色問題

- (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"]; 
} 

我遇到的問題是,有從層黑色形狀引起的顏色爲關閉:

enter image description here

我該怎麼做才能讓背景全部變成黃色的「mdvdYellow」而沒有背後的黑色呢?

預先感謝您。

回答

2

您需要從形狀圖層中刪除fillColor,因爲默認值是不透明的黑色。

設置fillColornil導致沒有填充被渲染。

self.circle.fillColor = nil;