Question

I have the stroke animation:

- (void)drawBezierAnimate:(BOOL)animate
{

UIColor* color = [UIColor colorWithRed: 1 green: 0.562 blue: 0.343 alpha: 1];

UIBezierPath *bezierPath = [self bezierPath];


CAShapeLayer *bezier = [[CAShapeLayer alloc] init];

bezier.path          = bezierPath.CGPath;
bezier.lineCap       = kCALineCapRound;
bezier.strokeColor   = color.CGColor;
bezier.fillColor     = [UIColor clearColor].CGColor;
bezier.strokeStart   = 1.0;
bezier.strokeEnd     = 0.0;
bezier.lineWidth     = 8.0;
bezier.strokeStart   = 0.0;
bezier.strokeEnd     = 1.0;
[self.view.layer addSublayer:bezier];


if (animate)
   {
    CABasicAnimation *animateStrokeStart = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
    animateStrokeStart.duration  = appDelegate.myPlayer.audioPlayer.duration;
    animateStrokeStart.fromValue = [NSNumber numberWithFloat:1.0f];
    animateStrokeStart.toValue   = [NSNumber numberWithFloat:0.0f];
    [bezier addAnimation:animateStrokeStart forKey:@"strokeStartAnimation"];
   }
}

Animation works perfect, but I am getting the errors:

<Error>: CGContextSetStrokeColorWithColor: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextSetLineWidth: invalid context 0x0
<Error>: CGContextSetLineJoin: invalid context 0x0
<Error>: CGContextSetLineCap: invalid context 0x0
<Error>: CGContextSetMiterLimit: invalid context 0x0
<Error>: CGContextSetFlatness: invalid context 0x0
<Error>: CGContextAddPath: invalid context 0x0
<Error>: CGContextDrawPath: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0

Path for animation is:

   - (UIBezierPath *)bezierPath
{


    //// Color Declarations
    UIColor* color0 = [UIColor colorWithRed: 0.756 green: 0.756 blue: 0.756 alpha: 0.6];



    //// Bezier Drawing
    UIBezierPath* bezierPath = [UIBezierPath bezierPath];


    [bezierPath moveToPoint: CGPointMake(213.79, 170.83)];
    [bezierPath addCurveToPoint: CGPointMake(131.93, 95) controlPoint1: CGPointMake(212.14, 128.68) controlPoint2: CGPointMake(176.13, 95)];
    [bezierPath addCurveToPoint: CGPointMake(50, 173.85) controlPoint1: CGPointMake(86.68, 95) controlPoint2: CGPointMake(50, 130.3)];
    [bezierPath addCurveToPoint: CGPointMake(131.93, 252.7) controlPoint1: CGPointMake(50, 217.4) controlPoint2: CGPointMake(86.68, 252.7)];
    [bezierPath addCurveToPoint: CGPointMake(157.55, 248.76) controlPoint1: CGPointMake(140.88, 252.7) controlPoint2: CGPointMake(149.49, 251.32)];
    [bezierPath addCurveToPoint: CGPointMake(209.69, 281) controlPoint1: CGPointMake(166.59, 267.78) controlPoint2: CGPointMake(186.54, 281)];
    [bezierPath addCurveToPoint: CGPointMake(267, 225.85) controlPoint1: CGPointMake(241.34, 281) controlPoint2: CGPointMake(267, 256.31)];
    [bezierPath addCurveToPoint: CGPointMake(213.79, 170.83) controlPoint1: CGPointMake(267, 196.71) controlPoint2: CGPointMake(243.53, 172.86)];
    [bezierPath closePath];


    [color0 setStroke];
    bezierPath.lineWidth = 11;
    [bezierPath stroke];

    return bezierPath;
}

I know that I need to get currentContext if I want something to draw, but this is an animatiom and I even don't have drawRect:

How to get rid of these annoying errors?

Was it helpful?

Solution

The problem rests with the bezierPath method. Remove the lines that say:

[color0 setStroke];
bezierPath.lineWidth = 11;
[bezierPath stroke];

The CAShapeLayer does all of the drawing for you. The bezierPath should just define the path, itself, but not perform any of the visual rendering. Let CAShapeLayer do that for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top