作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个绘图应用程序。其中一项功能是多色线条图。它应该像用户触摸屏幕并在其上画一条线一样工作。线条的颜色平滑地变化。像那样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;
}
谢谢你的帮助
最佳答案
具体取决于什么颜色、它们如何变化以及您想要什么效果/线路转弯会发生什么,您可能需要查看以下组合:
CGContextDrawLinearGradient
对用户绘制的路径进行屏蔽。colorWithPatternImage:
CGContextDrawLinearGradient
在另一层后面绘制,并使用 kCGBlendModeClear
关于iphone - 多色线描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18946965/
我是一名优秀的程序员,十分优秀!