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