无法摆脱bezier路径上的尖峰 [英] Unable to get rid of spike on bezier path

查看:120
本文介绍了无法摆脱bezier路径上的尖峰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制一些简单的bezier路径,但我发现当线段之间的角度很小时,我无法消除所产生的尖峰:

I'm drawing some simple bezier paths, but I'm finding it impossible to remove the spikes created when the angle between line segments is small:

(注意:圆圈来自一个单独的绘图操作,但我试图确保线不会超过圆圈...)。

(Note: The circle is from a separate drawing operation, but I'm trying to make sure the line does not spike past the circle...).

我尝试了各种各样的变化lineCapStyle和lineJoinStyle似乎没什么用。
除了下面显示的内容之外,我还尝试使用'setMiterLimit'进行斜接连接。

I've tried all kinds of variations of lineCapStyle and lineJoinStyle but nothing seems to work. In addition to what is shown below I have tried using a Miter Join with 'setMiterLimit'.

这是我的线条图代码片段:

Here's my line drawing code snip:

CAShapeLayer *myShapeLayer=[CAShapeLayer layer];
UIBezierPath *myPath=[UIBezierPath bezierPath];
[myPath moveToPoint:tmpPoint];
[myPath addLineToPoint:tmpPoint];         
[myPath setLineCapStyle:kCGLineCapRound];
[myPath setLineJoinStyle:kCGLineJoinRound];

myShapeLayer.path=[myPath CGPath];
myShapeLayer.strokeColor = [[UIColor yellowColor] CGColor];
myShapeLayer.fillColor = [[UIColor clearColor] CGColor];
myShapeLayer.lineWidth = 3.0;

以防万一 - 这是我使用的斜接代码,将值变为0.0到100.0 - 一切都没有效果:

Just in case - here's the Miter code I've used, varying the value rom 0.0 to 100.0 - all with no effect:

[myPath setLineCapStyle:kCGLineCapRound];
[myPath setLineJoinStyle:kCGLineJoinMiter];
[myPath setMiterLimit:1.0];


推荐答案

你应该设置 lineJoin 在形状图层而不是路径上:

You should be setting lineJoin on the shape layer instead of the path:

myShapeLayer.lineJoin = kCALineJoinRound;






混淆来自UIBezierPath拥有的绘制路径的能力(通过在路径上调用 fill stroke )。路径上的线连接和线帽的配置仅影响此绘图。


The confusion comes from the fact that UIBezierPath has the ability to draw the path (by calling fill and stroke on the path). The configuration of line joins and line caps on the path is only affecting this drawing.

但是,由于您是使用CAShapeLayer绘制路径,因此应在形状图层上完成线连接和线帽的配置。

However, since you are drawing the path using a CAShapeLayer, the configurations of both line joins and line caps should be done on the shape layer.

这篇关于无法摆脱bezier路径上的尖峰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆