大佬教程收集整理的这篇文章主要介绍了ios – 如何填充Quartz 2D中路径下方的区域?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我现在的代码(我省略了控制点和其他东西的计算):
for (int i = 1; i < points.count; ++i) { CGContextMoveToPoint(context,prevIoUsXValue,prevIoUsYvalue); CGContextAddCurveToPoint(context,firstControl@R_352_7616@Value,firstControlpointyValue,secondControl@R_352_7616@Value,secondControlpointyValue,xValue,yValue ); // CGContextFillPath(context); CGContextstrokePath(context); }
现在我想填充曲线下方的区域,但如果我使用CGContextFillPath,结果如下:
这是有道理的,因为根据Quartz 2D documentation:
然后我尝试将路径移动到右下角并关闭路径,但填充方法没有任何影响:
CGContextMoveToPoint(context,rect.size.width,rect.size.height); CGContextClosePath(context); CGContextFillPath(context);
我怎样才能填满曲线下面的整个区域而不仅仅是在每个子路径中关闭的子区域?
编辑:
我找到了一个临时解决方案:使用曲线绘制形状,并在每个子路径上绘制两条垂直线:
for (int i = 1; i < points.count; ++i) { // Draw the curve CGContextMoveToPoint(context,yValue ); CGContextstrokePath(context); // Draw a shape using curve's initial and final points CGContextMoveToPoint(context,rect.size.height); CGContextAddLineToPoint(context,yValue ); CGContextAddLineToPoint(context,rect.size.height); CGContextFillPath(context); }
我不知道这是否过度,所以也欢迎改进.此外,我得到了这个结果:
请注意,垂直线显示为绘制彼此相邻的子区域的结果.怎么可以避免?
- (void)drawRect:(CGRect)rect { if (!self.points) [self configurePoints]; DataPoint *point; CGContextRef context = UIGraphicsGetCurrentContext(); CGColorRef color = [[UIColor redColor] CGColor]; CGContextSetstrokeColorWithColor(context,color); CGContextSetFillColorWithColor(context,color); point = self.points[0]; CGContextMoveToPoint(context,point.x,self.bounds.size.height); CGContextAddLineToPoint(context,point.y); for (point in self.points) { // you'd do your CGContextAddCurveToPoint here; I'm just adding lines CGContextAddLineToPoint(context,point.y); } point = [self.points lastObject]; CGContextAddLineToPoint(context,self.bounds.size.height); CGContextClosePath(context); CGContextDrawPath(context,kCGPathFillstroke); }
以上是大佬教程为你收集整理的ios – 如何填充Quartz 2D中路径下方的区域?全部内容,希望文章能够帮你解决ios – 如何填充Quartz 2D中路径下方的区域?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。