如何使用 CGContext 在现有 UIView 之上进行绘制?
我有一个 UIView
的子类,其中我在 initWithFrame
方法中添加了一些子视图。除其他外,我还添加了背景。
我想在这些视图之上绘制一些形状(恰好覆盖整个屏幕)。但是,当我实现 drawRect:
来绘制这些形状时,它们没有显示出来。删除其他子视图后,我意识到形状是在其他子视图“下方”开始绘制的。
我怎样才能把它们画在上面?
I have a subclass of UIView
in which I've added some subviews to in my initWithFrame
method. I've added a background, amongst other things.
I want to draw some shapes on top of these views (which happen to cover the entire screen). But, when I implement drawRect:
to draw these shapes, they didn't show up. Upon removing the other subviews, I realized that the shapes were begin drawn "under" the other subviews.
How can I draw them on top?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在所属视图的
drawRect:
开头调用[super drawRect:rect]
。这会将所有子视图绘制到当前上下文中。然后,您为所属视图所做的其他绘图应该位于顶部。Call
[super drawRect:rect]
at the beginning of thedrawRect:
for the owning view. This will draw all the subviews into the current context. Additional drawing you do for the owning view should then go on top.也许,您应该在其他视图之上添加透明视图并在其上绘制形状?
Maybe, you should add transparent view on top of others and draw shapes on it?