iOS 连续绘图而不擦除先前绘制的内容

发布于 2024-10-28 23:05:01 字数 196 浏览 1 评论 0原文

我只是想根据用户交互在视图上绘制一堆线条。例如,用户按下一个按钮,然后绘制一条线。用户按下另一个按钮,会绘制另一条线,但第一条线仍然存在,依此类推。这似乎是一项微不足道的任务,但从我所读到的内容来看,非破坏性绘图并不是很简单。谁能引导我走向正确的方向,最好是一些示例代码?当然,任何形式的指导都是非常感谢的。从字面上看,只需要不断在视图上绘制各种直线即可。预先感谢您的任何帮助!

I am simply trying to draw a bunch of lines to a view, depending on user interaction. For example, the user presses a button, and one line is drawn. The user presses another button, and another line is drawn, but the first one is still there, and so on. It seems like a trivial task, but from what I've been reading, non-destructive drawing is not very straightforward. Can anyone guide me in the right direction, ideally towards some sample code? Any kind of guidance is really appreciated though, of course. Literally just need to keep drawing various straight lines onto a view. Thanks in advance for any help!

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

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

发布评论

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

评论(2

绿光 2024-11-04 23:05:01

如果你想使用 Quartz Core,我相信你每次都必须重新绘制整个东西......所以有人添加一条线,你绘制这条线,他们添加另一条线,你添加两条线等等......但您也许可以在图层上绘图并将它们不断添加到彼此的顶部..

If you want to use Quartz Core, i believe you will have to re draw the whole thing every time...So someone adds a line, you draw the line, they add another line, you add both lines and so on...but you might be able to draw on layers and keep adding them on top of each other..

美人骨 2024-11-04 23:05:01

如果您不需要撤消功能,请尝试绘制到 CGBitmapContext ,然后从中创建图像并根据需要将其渲染到屏幕。这称为“后台缓冲”(或“双缓冲”或“缓冲绘图”)并且很常见。

If you don't need undo capability, try drawing to a CGBitmapContext, then creating an image from it and rendering that to the screen as needed. This is called "back buffering" (or "double buffering" or just "buffered drawing") and is very common.

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