2015-05-04 2 views
0

Я использую 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: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

+1

http://stackoverflow.com/questions/19599266/invalid-context -0x0-under-ios-7-0-system-demation –

ответ

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]; 
+0

Я использовал ваш второй способ. это сработало. Большое вам спасибо – thinhvd

+0

@thinhvd omit [aPath fill]; –

0

Добавить это как в setStrokeColor

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

+0

Не работает – thinhvd

+0

Вы заменили его на '[[UIColor redColor] setStro ke]; – Mrunal

+0

да, я сделал. но все еще с ошибкой – thinhvd

0

Попробуйте это: В Xcode оных символическая точка останова до CGPostError. (Добавить символическую точку останова и в поле типа символа CGPostError)

При возникновении ошибки отладчик прекратит выполнение кода, и вы можете проверить стек вызовов методов и проверить параметры.

Также убедитесь, что вы импортировали QuartzCode рамки.

Смежные вопросы