改变CAShapeLayer中的lineWidth

don*_*kim 4 iphone core-animation objective-c

我正在做一个小项目,我想绘制一条bezier曲线.我希望能够改变lineWidth图纸的不同部分.

这就是我所拥有的:

CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.animationLayer.bounds;
pathLayer.bounds = pathRect;
pathLayer.geometryFlipped = YES;
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 1.0f;
pathLayer.lineJoin = kCALineJoinBevel;
Run Code Online (Sandbox Code Playgroud)

我该如何改变线条的宽度?一种解决方案可能是使多个UIBezierPaths具有多个CAShapeLayers,但似乎应该有一个更简单,更优雅的解决方案(在指定行指定lineWidth的级别的UIBezierPath某些方面).

谢谢!

omz*_*omz 6

UIBezierPath只有一个lineWidth属性,所以不可能用一条路径绘制不同的线宽.您必须使用多个路径才能实现此效果.