2013-02-22 246 views
1

我能在我的應用程序中使用UIBezierPath進行繪製。現在我添加了一個UIColor變量,以便用戶按下按鈕可以選擇不同的顏色。當用戶改變顏色並且開始用新顏色繪製時,所有已經繪製的路徑都具有新的顏色。UIBezierPath不同的顏色

如何告訴對象不要更改已經繪製的路徑的顏色?

這是我的代碼。任何代碼的例子非常感謝! :)

(我有我的UIColor變量中的appDelegate蓄能和我打電話從其他viewControlle刷新方法。

- (id)initWithFrame:(CGRect)frame 
{ 
self = [super initWithFrame:frame]; 
if (self) { 

    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 


    self.backgroundColor = [UIColor whiteColor]; 
    myPath = [[UIBezierPath alloc] init]; 
    myPath.lineCapStyle = kCGLineCapRound; 
    myPath.miterLimit = 0; 
    myPath.lineWidth = 5; 

    brushPattern = app.currentColor; 

} 
    return self; 
} 
-(void)refresh { 
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

    brushPattern = app.currentColor; 
} 



- (void)drawRect:(CGRect)rect { 
    [brushPattern setStroke]; 
    for (UIBezierPath *_path in pathArray) 
    [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0]; 
} 


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    myPath = [[UIBezierPath alloc] init]; 
    myPath.lineWidth = 5; 

    UITouch *mytouch = [[touches allObjects] objectAtIndex:0]; 
    [myPath moveToPoint:[mytouch locationInView:self]]; 
    [pathArray addObject:myPath]; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *mytouch = [[touches allObjects] objectAtIndex:0]; 
    [myPath addLineToPoint:[mytouch locationInView:self]]; 
    [self setNeedsDisplay]; 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

} 
+0

你已經得到任何解決方案?如果您已經然後回答後,因此,這將是有幫助給別人.. – 2013-04-08 13:33:26

+0

不,對不起。我需要改變系統... – BalestraPatrick 2013-04-08 15:40:03

回答

0

我找到了一個演示代碼爲..

請檢查此它是否會有所幫助你..

Smooth Line鏈接

+0

謝謝!它看起來真棒:) – BalestraPatrick 2013-04-09 09:45:39

+0

然後接受答案..所以其他人可以從這裏得到幫助.. – 2013-04-09 14:54:42