Я разрабатываю приложение блокировки шаблонов (например, Android lock).CGContextAddLineToPoint: нет текущей точки
Я хочу, чтобы рисовать линии между точками, чтобы открыть замок, но когда я рисую, он возвращает ошибку:
<Error>: CGContextAddLineToPoint: no current point
Он работает отлично в прошивкой 5.0 и раньше, но он показывает ошибку в 5.1.
Это мой код:
- (void)drawRect:(CGRect)rect
{
NSLog(@"drawrect...%@",NSStringFromCGRect(rect));
if (!self._trackPointValue)
return;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 10.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.5, 1.0, 0.5, 0.8};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context, color);
CGPoint from;
UIView *lastDot;
for (UIView *dotView in self._dotViews) { //_dotViews array of points
from = dotView.center;
if (!lastDot)
{
CGContextMoveToPoint(context, from.x, from.y);
}
else
{
NSLog(@"from : %@",NSStringFromCGPoint(from));
CGContextAddLineToPoint(context, from.x, from.y);
}
lastDot = dotView;
}
CGPoint pt = [self._trackPointValue CGPointValue]; //_trackPointValue is current point
CGContextAddLineToPoint(context, pt.x, pt.y);
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);
CGColorRelease(color);
self._trackPointValue = nil;//_trackPointValue is current point
}
Неправда. CGContext всегда имеет текущий путь (возможно, пустой), к которому вы можете добавить элементы. Вам нужно 'CGContextBeginPath' только тогда, когда вы хотите отменить текущий путь и начать с нового пустого пути. –
Я этого не знал, спасибо. –