我应该使用哪种算法来更改/修改曲线

发布于 2024-12-23 08:54:38 字数 201 浏览 4 评论 0原文

我制作了一个使用 UIBezierPath 绘制多条曲线的应用程序。现在我正在尝试在其中实现修改功能。要修改特定曲线,我可以做的一件事就是再次绘制所有曲线;我还没有实现这个。但我认为当曲线数量增加时,这个算法不会很有效,因为我必须将所有点存储在数组中,并且每次修改时都必须运行 for 循环来绘制每条曲线。

我正在寻找更有效的算法。如果有人可以提供示例代码,将会很有帮助。

I have made an application which draws a number of curves, using UIBezierPath. Now I'm trying to implement a modification functionality in it. To modify the particular curve one thing I can do is to draw all the curves again; I have not yet implemented this. But I think this algorithm would not be very efficient when the number of curves increases because I have to store all the points in the array and I have to run for loop to draw each curve every time I go for modification.

I am looking for more efficient algorithm. It will be helpful if someone can provide example code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

意中人 2024-12-30 08:54:39

您可以将各个曲线表示为 UIBezierPath 并通过为每条曲线创建一个 CAShapeLayer 并将形状层的 path 属性分配给相应的 CAShapeLayer 来单独绘制它们。贝塞尔路径的 code>CGPath 属性。要更新一条曲线,您只需操作一条贝塞尔曲线路径和相应的形状图层 path 属性即可。

You can represent individual curves as UIBezierPaths and draw them separately by creating one CAShapeLayer per curve and assigning the shape layer's path property to the corresponding CGPath property of the bezier path. To update an individual curve, you then just have to manipulate one bezier path and the corresponding shape layers path property.

喜你已久 2024-12-30 08:54:39

重新绘制曲线,直到出现使用仪器测量的性能问题。如果这种情况再次发生,请使用仪器来查明最佳优化方法。

人们很容易陷入将时间花在根本不需要的优化上。最初,最好花时间和思考来创建“干净”的代码。

Redraw the curve until you have a performance problem as measured with Instruments. If that occurs again use Instruments to pinpoint the best way to optimize.

It is easy to get sucked into spending time on optimizations that are never needed. Initially it is much better to put that time and thinking into creating a "clean" code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文