如何将 Quartz 2d 绘图集成到 UIView 子视图中?
我的主 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个视图都需要它自己的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.