加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – CGContextAddLineToPoint:没有当前点

发布时间:2020-12-14 20:01:23 所属栏目:百科 来源:网络整理
导读:我正在开发一个模式锁定应用程序(如 Android锁定). 我想在点之间画线来打开锁,但是当我画画时,它会返回一个错误: 错误:CGContextAddLineToPoint:没有当前点 它在iOS 5.0和之前的工作正常但它在5.1中显示错误. 这是我的代码: - (void)drawRect:(CGRect)re
我正在开发一个模式锁定应用程序(如 Android锁定).

我想在点之间画线来打开锁,但是当我画画时,它会返回一个错误:

<错误>:CGContextAddLineToPoint:没有当前点

它在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.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
 }

解决方法

要获得当前点,您必须确保在CGContextAddLineToPoint开始运行之前至少调用一次CGContextMoveToPoint.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读