Par*_*dhu 9 iphone xcode xcode4 ios5 xcode4.2
我正在开发一个模式锁定应用程序(如Android锁定).
我想在点之间画线来打开锁,但是当我画画时,它会返回一个错误:
<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
}
Run Code Online (Sandbox Code Playgroud)
您必须先创建一条路径,CGContextBeginPath
然后才能开始向其中添加点和线。
归档时间: |
|
查看次数: |
8234 次 |
最近记录: |