繁体   English   中英

更改贝塞尔曲线的颜色

[英]Changing the color of the bezier curve

以下是用于释放手绘图的代码。 但是每次我更改画笔的颜色时,新的颜色也会应用于以前的曲线。 为什么会这样呢?

    - (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];


}

因为您要重新绘制drawRect中的所有路径,所以所有路径都具有相同的颜色(brushPattern)。 如果您使用不同颜色的路径,则必须存储绘图时使用的颜色,并将其设置为绘图循环中的笔触颜色。

我建议您的pathArray包含字典,每个字典都具有路径和颜色,而不是仅包含路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM