簡體   English   中英

CABasicAnimation動畫中的上下文錯誤

[英]Context errors in CABasicAnimation 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"];
   }
}

動畫效果完美,但出現錯誤:

<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

動畫路徑為:

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

我知道如果我想繪制一些東西,我需要獲取currentContext,但這是一個動畫,我什至沒有drawRect:

如何擺脫這些煩人的錯誤?

問題在於bezierPath方法。 刪除以下行:

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

CAShapeLayer為您完成所有工程圖。 bezierPath應該只定義路徑本身,而不執行任何視覺呈現。 CAShapeLayer為您做到這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM