2013-09-22 65 views
0

我正在創建一個繪圖應用程序。其中一個特點是多色線條畫。它應該像使用者觸摸屏幕一樣工作,並引導它畫出一條線。線的顏色變化平穩。像那樣http://www.examples.pavelgatilov.com/Screen%20Shot%202013-09-22%20at%208.37.42%20PM.png多色線條圖

我嘗試了幾種方法,但都沒有幸運。

我的畫線方法如下:

- (void) drawLineFrom:(CGPoint)from to:(CGPoint)to width:(CGFloat)width 
{ 
self.drawColor = toolColor; 
UIGraphicsBeginImageContext(self.frame.size); 
CGContextRef ctx = UIGraphicsGetCurrentContext(); 
CGContextScaleCTM(ctx, 1.0f, -1.0f); 
CGContextTranslateCTM(ctx, 0.0f, -self.frame.size.height); 
if (drawImage != nil) { 
    CGRect rect = CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height); 
    CGContextDrawImage(ctx, rect, drawImage.CGImage); 
} 
CGContextSetLineCap(ctx, kCGLineCapRound); 
CGContextSetLineWidth(ctx, width); 
CGContextSetStrokeColorWithColor(ctx, self.drawColor.CGColor); 
CGContextMoveToPoint(ctx, from.x, from.y); 
CGContextAddLineToPoint(ctx, to.x, to.y); 
CGContextStrokePath(ctx); 
CGContextFlush(ctx); 
drawImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
drawLayer.contents = (id)drawImage.CGImage; 
} 

感謝您的幫助

回答

2

根據到底是什麼顏色,他們如何改變,你想要什麼樣的影響/什麼在符合輪番發生,你可能想看看下面的一些組合:

  • CGContextDrawLinearGradient掩蓋了用戶繪製的路徑。
  • colorWithPatternImage:
  • CGContextDrawLinearGradient後面另一個層和繪圖透明度到頂層繪製kCGBlendModeClear
+0

感謝的想法 –