所以我在 iOS 中做这个绘画应用程序,我有一个问题......
现在我在用户点击的地方画了一个圆圈...但这就是问题所在。当用户再次点击时,第一个圆圈将移动到新位置。我想做的是在那个位置画一个新的圆圈,而不是移动旧的圆圈。
我正在使用一些标准代码,这些代码在网络上的许多示例中都在使用...
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *theTouch = [touches anyObject];
startPoint = [theTouch locationInView:self];
startPoint.x -= 20;
startPoint.y -= 20;
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGRect rectangle = CGRectMake(startPoint.x,startPoint.y,25,25);
CGContextAddEllipseInRect(context, rectangle);
CGContextFillEllipseInRect(context, rectangle);
CGContextStrokePath(context);
}
我知道这可能是一个非常菜鸟的问题 :) 此外,如果有人可以指出教程的方向或解释如何在之后保存我的图像的内容,那也将非常有帮助...
最佳答案
您需要跟踪所有点击位置的历史记录,并在 drawRect 方法中的每个位置绘制一个圆圈。
要保存为图像,您需要绘制到位图上下文,请查看 Apple 的 Quartz 2D 编程指南以了解如何操作的示例。
关于iOS:绘图应用程序 - 绘制圆圈,但新圆圈取代旧圆圈 - 保存状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5807667/