具有拐角半径的UIBezierPath,具有strokeStart的偏移量

时间:2018-11-01 23:33:23

标签: ios uibezierpath

这是我创建形状的方式

self.shape = [CAShapeLayer layer];
[self.shape setPath:[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, frame.size.width, frame.size.height) cornerRadius:9.0f].CGPath];
self.shape.strokeColor=[UIColor purpleColor].CGColor;
self.shape.fillColor=[UIColor clearColor].CGColor;
self.shape.lineWidth = 7.0f;
self.shape.lineCap = kCALineCapSquare;
self.shape.lineJoin=kCALineJoinRound;

这是我获取路径比例的方法

CGFloat length=(frame.size.width*2)+(frame.size.height*2);
CGFloat scale=1/length;

框架是一个盒子。我正在尝试在方框右侧的中间开始笔划,并在左侧中间结束。像这样____ |由于strokeStart=0从框的左上角开始,所以我这样做了:

[self.shape setStrokeStart:(scale*(frame.size.width+(frame.size.height/2)))];
[self.shape setStrokeEnd:(scale*((frame.size.width*2)+frame.size.height+(frame.size.height/2)))];

如果我将UIBezierPath的拐角半径设置为0,那么一切都是偶数。设置为9时,即使strokeStart设置为0,它也会偏移圆角。

我尝试了类似的操作(-9和+9),但仍然不平衡。

[self.shape setStrokeStart:(scale*(frame.size.width+(frame.size.height/2)-9))];
[self.shape setStrokeEnd:(scale*((frame.size.width*2)+frame.size.height+(frame.size.height/2)+9))];

cornerRadius> 0时,如何考虑strokeStart中的微小偏移?

0 个答案:

没有答案