如何将 Quartz 2d 绘图集成到 UIView 子视图中?

发布于 2024-09-28 01:00:00 字数 232 浏览 1 评论 0原文

我的主 UIView 中有一个 drawrect 方法,它在每个游戏中绘制 8 个精灵。我想将每个精灵分离到一个单独的 UIView 中。

我想先拆分一个精灵作为测试。

到目前为止,我已经将 UIView 作为子视图添加到我的主视图中并设置了它的框架。这会在视图上绘制一个黑框。我的问题是我现在如何在 drawrect 方法中获取精灵绘图以绘制到此 UIView 中?

谢谢大家,

马丁

I have a drawrect method in my main UIView which draws 8 sprites every game tic. I want to seperate out each of these sprites into a seperate UIView.

I am trying to split out one sprite first as a test.

So far I have added a UIView as subview to my main view and set it's frame. This draws a black box on the view. My question is how do I now get get the sprite drawing in the drawrect method to draw into this UIView ?

Thanks all,

Martin

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

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

发布评论

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

评论(1

街角卖回忆 2024-10-05 01:00:01

每个视图都需要它自己的drawRect,并且在某个地方您需要在每个可见的(子)视图上调用setNeedsDisplay。在您希望其出现的视图的drawRect 中绘制精灵。您可以拥有许多子类化的 uiview,每个都有自己的 drawRect,也可以在 drawRect 内使用 switch case 语句,根据某种类型的子视图属性选择要绘制的内容。

您可能还想将精灵视图的背景颜色设置为透明,以便在您绘制它们之前它们是不可见的。

Each view will need it's own drawRect, and somewhere you will need to call setNeedsDisplay on every (sub)view visible. Draw the sprite in the drawRect for the view where you want it to appear. You can either have lots of subclassed uiviews, each with their own drawRect, or a switch case statement inside a drawRect that selects what to draw based on some sort of type-of-subview property.

You might also want to set your sprite's view's background color to transparent, so that they are invisible until you draw into them.

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