私はAndroidロックのようなパターンロックアプリケーションを開発しています。CGContextAddLineToPoint:現在のポイントがありません
私はロックを開くためのポイントの間に線を描きたいが、私が描いていたとき、それはエラーを返します:
<Error>: CGContextAddLineToPoint: no current point
それは、iOS 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'が必要なのは、現在のパスを破棄し、新しい空のパスで開始する場合だけです。 –
私はそれを知らなかった、ありがとう。 –