我正在尝试使用UIBezierPath绘制长方体形状。我的绘图代码如下:

((x,y)是我的UIView的原点,而(h,w)是它的大小)

UIBezierPath *bpath1 = [UIBezierPath bezierPath];
[bpath1 moveToPoint:CGPointMake(x, y + h * 0.4)];
[bpath1 addLineToPoint:CGPointMake(x, y + h)];
[bpath1 addLineToPoint:CGPointMake(x + w - (w * 0.4), y + h)];
[bpath1 addLineToPoint:CGPointMake(x + w - (w * 0.4), y + h * 0.4)];
[bpath1 closePath];


UIBezierPath *bpath2 = [UIBezierPath bezierPath];
[bpath2 moveToPoint:CGPointMake(x + w * 0.4, y)];
[bpath2 addLineToPoint:CGPointMake(x + w, y)];
[bpath2 addLineToPoint:CGPointMake(x + w - (w * 0.4), y + h * 0.4];
[bpath2 addLineToPoint:CGPointMake(x, y + h * 0.4];
[bpath2 closePath];

UIBezierPath *bpath3 = [UIBezierPath bezierPath];
[bpath3 moveToPoint:CGPointMake(x + w, y)];
[bpath3 addLineToPoint:CGPointMake(x + w, y + h - (h * 0.4))];
[bpath3 addLineToPoint:CGPointMake(x + w - (w * 0.4), y + h)];
[bpath3 addLineToPoint:CGPointMake(x + w - (w * 0.4), y + h * 0.4];
[bpath3 closePath];


我创建了3条路径,因为我希望每个路径都具有不同的alpha值。我得到所需的输出如下:



但是令我惊讶的是h(height)的值很少,我得到的形状如下:



现在,出现这种形状的值的数量很少。由于每次渲染代码都是相同的,所以我不理解贝塞尔曲线路径的这种奇怪行为。为什么贝塞尔曲线显示这种行为,并且有什么方法可以使这些关节光滑?

最佳答案

看一下lineCapStylelineJoinStyle。具体来说,我认为这是因为lineJoinStyle默认为Mitre,并且将其更改为Round或更改miterLimit

我相信这与UIBezierPath not drawing a smooth curve具有相同的解决方案

08-26 03:56