使用UIBezierPath绘图控制台<Eorro>CGContextSaveGState: invalid context 0x0,CGContextSetLineWidth: invalid co

真机调试,控制台打印的结果:


模拟器调试,控制台打印的结果:


代码:

UIBezierPath * bezierPath = [UIBezierPath bezierPathWithRoundedRect:(CGRect){5,5,self.bounds.size.width-10,self.bounds.size.height-10} cornerRadius:(self.bounds.size.height-10)/2];
    bezierPath.lineWidth = 2.0;
    bezierPath.lineCapStyle = kCGLineCapRound;
    bezierPath.lineJoinStyle = kCGLineCapRound;
//    [bezierPath stroke];   //如果控制台出现<Error>: CGContextSaveGState: invalid context 0x0.错误则注释掉
    
    //遮罩层
    
    CAShapeLayer * progressLayer = [CAShapeLayer layer];
    
    progressLayer.frame = self.bounds;
    
    progressLayer.fillColor =  [[UIColor clearColor] CGColor];
    
    progressLayer.strokeColor=[UIColor orangeColor].CGColor;

    progressLayer.lineWidth = 11;
    
    CALayer * grain = [CALayer layer];
    CAGradientLayer * gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    
    [gradientLayer setColors:[NSArray arrayWithObjects:(id)[selfBgColor CGColor],(id)[selfBgColor CGColor], nil]];
    
    [gradientLayer setLocations:@[@0.3,@1]];
    
    [gradientLayer setStartPoint:CGPointMake(0.9, 0.05)];
    
    [gradientLayer setEndPoint:CGPointMake(1, 1)];
    [grain addSublayer:gradientLayer];
    
    //用progressLayer来截取渐变层 遮罩
    
    
    [grain setMask:progressLayer];
    
    [self.layer addSublayer:grain];
    
    
    //增加动画
    
    CABasicAnimation *pathAnimation=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    
    pathAnimation.duration = self.countDownTime ;
    
    pathAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    
    pathAnimation.fromValue=[NSNumber numberWithFloat:0.0f];
    
    pathAnimation.toValue=[NSNumber numberWithFloat:1.0f];
    
    pathAnimation.autoreverses = NO;
    pathAnimation.repeatCount = 0;
    progressLayer.path=bezierPath.CGPath;
    [progressLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"];




问题解决方法:

不要实现 - (void)stroke 方法 ;


效果图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值