如何绘制可变宽度的 UIBezierPath?
我想知道应该如何绘制一条 uibezierpath,其中笔划宽度在圆弧中心达到峰值。这是我的意思的一个例子:
要么我必须在绘制时遍历每个点,并相应地设置描边宽度,或者有更简单的方法。有人能指出我正确的方向吗?
谢谢
I'm wondering how I should go about drawing a uibezierpath where the stroke width peaks at the center of the arc. Here's an example of what I mean:
Either I have to go through each point when drawing, and set the stroke width accordingly, or there's an easier way. Can anyone point me in the right direction?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以只绘制两条没有描边的外部路径,将它们连接起来,然后填充它们之间的空间。
You can just draw the two outer paths with no stroke, join them, and then fill in the space between them.
如果您感兴趣,可以尝试此方法的另一种方法:
我最终通过创建一个循环来绘制数百条线段并在绘制循环期间相应地更改线宽来使其工作。
为了调整线宽,我使用了以下函数: MAX_WIDTH * sinf(M_PI * (i/NUMBER_OF_SEGMENTS)
看起来很棒,据我所知没有性能问题。效果特别好,因为我已经有了要使用的点列表对于其他情况,我猜使用索斯伯恩的方法会更好。
Another way to try this if you're interested:
I ended up getting this to work by creating a loop to draw a couple hundred line segments, and changing the line width accordingly during the draw loop.
To adjust the line width I used the following function: MAX_WIDTH * sinf(M_PI * (i/NUMBER_OF_SEGMENTS)
Looks great and no performance issues as far as I can tell. Worked out particularly well because I already had a list of the points to use on the curve. For other cases I'm guessing it would be better to use sosborn's method.