使用UIBezierPath时出错

时间:2015-05-04 07:00:24

标签: ios objective-c cgcontext uibezierpath

我使用UIBezierPath画一条线。但是有一个错误 这是我的代码:

UIBezierPath *aPath = [UIBezierPath bezierPath];
[aPath moveToPoint:CGPointMake(100, 100)];
[aPath addLineToPoint:CGPointMake(200, 200)];
[aPath closePath];
aPath.lineWidth = 5;
[[UIColor redColor] setStroke];
[aPath stroke];

这是错误:

  

CGContextSetStrokeColorWithColor:无效的上下文0x0。这是一个   严重错误。此应用程序或它使用的库正在使用   无效的上下文,从而导致整体退化   系统稳定性和可靠性。这个通知是礼貌的:拜托   解决这个问题。在即将到来的更新中,它将成为一个致命的错误。

3 个答案:

答案 0 :(得分:1)

而不是

[[UIColor redColor] setStroke];

使用

CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);

你也可以这样做 -

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
UIBezierPath *aPath;

aPath = [UIBezierPath bezierPath];
[aPath moveToPoint:CGPointMake(0, 0)];
[aPath addLineToPoint:CGPointMake(size*2, 0)];
[aPath addLineToPoint:CGPointMake(size, size*2)];
[aPath closePath];

shapeLayer.path = aPath.CGPath;
shapeLayer.strokeColor = [[UIColor redColor] CGColor];
shapeLayer.fillColor = color;
shapeLayer.lineWidth = width;

[self addSublayer:shapeLayer];

答案 1 :(得分:0)

将此添加到 setStrokeColor

var Gandalf = new Character("Gandalf", "wizzard", 50, 15, 8); function Character(name, characterClass, health, damage, heal){ this.name = name, this.characterClass = characterClass, this.health = health, this.damage = damage, this.heal = heal, this.dodge = Math.random() * 100 + 1; }

答案 2 :(得分:0)

试试这个:在xcode中添加符号断点到CGPostError。 (添加符号断点,并添加到符号字段类型CGPostError

发生错误时,调试器将停止执行代码,您可以检查方法调用堆栈并检查参数。

还要确保已导入QuartzCode框架。