如何使NSView透明,但留下属于它的对象,因为他们是? [英] How to make the NSView transparent, but leave objects belonging to it as they were?
问题描述
在我的应用程序中,我有一个NSView,我用作绘制画布来绘制一些原始的形状,如矩形和椭圆使用NSBezierPath。现在我需要让我的画布透明,但我想要我绘制的形状和以前相同的不透明度。我很好奇,如果它是可能做到的,如果是,如何?
In my app I have a NSView that I use as a drawing canvas to draw some primitive shapes like rects and ellipses using NSBezierPath. Right now I need to make my canvas transparent, but I want my shapes that I draw have the same opacity as they had before. I'm curious if it's possible to do it, and if it is, how?!
编辑:
对不起以前的描述!
我的最终目标是能够在透明画布上绘制正常的饱和色彩形状。透明我的意思是完全清楚如果这可能。当我绘制形状我的意见是重新绘制自己所有的时间,所以即使在这些条件下,我想要一切如上所述。
The ultimate goal for me is to be able to draw normal saturated-color shapes on the transparent canvas. By transparent I mean totally clear if this possible. When I draw shapes my view is redrawing itself all the time, so even under these conditions I want everything to be as described above.
任何种类的帮助是赞赏!
Any kind of help is appreciated!
推荐答案
要使一个窗口透明,使其后面的任何内容显示出来,设置窗口的 backgroundColor
到
[NSColor clearColor]
和窗口的 opaque
到 NO
。
To make a window transparent so that whatever's behind it shows through, set the window's backgroundColor
to [NSColor clearColor]
and the window's opaque
to NO
.
设置视图的 opaque
NO
默认情况下,因为这不是你要找的。视图的 opaque
属性意味着与Windows的 opaque
属性不同。
Setting the view's opaque
is unnecessary because it's already NO
by default, and because that doesn't do what you're looking for. The opaque
property of views means something different than the opaque
property of windows.
填充 clearColor
是不必要的,因为所有这一切都会删除您之前绘制的内容。
Filling with clearColor
is unnecessary because all that does is erase what you've previously drawn. If you haven't drawn anything there previously, you are erasing a clean board.
任何你的观点 绘制(这不是 clearColor
)仍然可见。
Anything your views do draw (that isn't clearColor
) will still be visible.
这篇关于如何使NSView透明,但留下属于它的对象,因为他们是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!