0
以下是我用来释放手绘的代码。但每当我改变画笔的颜色时,新的颜色也会应用到之前的曲线。这是为什么发生。更改贝塞尔曲线的颜色
- (void)drawRect:(CGRect)rect
{
for (UIBezierPath *_path in pathArray) {
[brushPattern setStroke];
_path.lineCapStyle = kCGLineCapRound;
[_path stroke];
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
isEdited=YES;
myPath=[[UIBezierPath alloc]init];
myPath.lineWidth=lineWidths;
CGPoint touchPoint = [[touches anyObject] locationInView:self];
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath moveToPoint:[mytouch locationInView:self]];
[myPath addLineToPoint:CGPointMake(touchPoint.x+1, touchPoint.y+1)];
[pathArray addObject:myPath];
[self setNeedsDisplay];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
}
我添加了NSMutableDictionary并添加了[dict setObject:brushPattern forKey:myPath]; [pathArray addObject:dict];在接触开始。我怎样才能在drawrect中迭代? –
我确实在字典中添加了颜色和路径,并且在字典中添加了字典。我正在获取该数组中的不同路径和颜色,但是当我绘制新路径时,即使不更改颜色,以前的路径也会消失。任何人都可以告诉我为什么会这样? –
你必须包含你的代码,也许在一个新的问题。 – jrturton