簡體   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