【问题标题】:Drawing with Quartz2D several 'Images' Array problem?用 Quartz2D 绘制几个“图像”数组问题?
【发布时间】:2011-07-31 11:52:35
【问题描述】:

我正在尝试制作一个简单的绘图应用 atm 来学习。据我所知:

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);
}

到目前为止一切正常,它在您触摸的地方进行绘制并将坐标累加到一个数组中。如果您停止触摸并在另一点触摸,它将连接您之前绘制的路径。我实际上不想要。所以我想在触摸结束后创建一个新数组。我完全错了还是那是正确的做事方向?有时我会错过编程的逻辑,但嘿,我还在学习!

提前致谢!

【问题讨论】:

    标签: iphone objective-c xcode quartz-2d


    【解决方案1】:

    如果你想收集你在一个数组中绘制东西的触摸,并且你还希望能够绘制单独的曲线,那么你应该在每个touchesBegan 处创建一个新数组。你也可以在 touchesEnd 中做到这一点,它并没有太大的不同。如果您确实需要将触摸坐标存储在数组中,我不确定,这取决于您的整体功能......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      • 2011-10-19
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多