用石英2D绘制几个'Images'阵列问题?



我正在尝试制作一个简单的绘图应用程序来学习。到目前为止,我得到了这个:

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, 2.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.0, 0.0, 0.0, 1.0};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context, color);
CGPoint firstPoint = [[self.array objectAtIndex: 0] CGPointValue];
CGContextMoveToPoint(context, firstPoint.x, firstPoint.y);
for (int i = 0; i < [self.array count]; i++) {
  CGPoint nextPoint = [[self.array objectAtIndex:i] CGPointValue];
   CGContextAddLineToPoint(context, nextPoint.x, nextPoint.y);
}
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);
CGColorRelease(color);
}

到目前为止一切都可以工作,它会在你触摸和添加数组坐标的地方绘图。如果你停止触摸,在另一个点上触摸,它会连接你之前画的路径。其实我不想这样。我想在触摸结束后创建一个新的数组。是我完全错了,还是这才是正确的做事方向?有时我错过了逻辑编程,但嘿,我还在学习!

提前感谢!

如果你想收集在数组中绘制物体的触摸,并且你还希望能够绘制单独的曲线,那么你应该在每个touchesBegan上创建一个新数组。你也可以在touchesEnd中这样做,差别不大。如果你真的需要在数组中存储触摸坐标,我不确定,这取决于你的整体功能…

最新更新