Background: My application has a main window which contains a few smaller NSView
objects, each of which contains several different controls, labels, images, etc. One of these views (and everything it contains) is disabled in response to a given flag. When the flag is set, I automatically disable and grey-out all of the controls embedded within that NSView
.
背景:我的应用程序有一个主窗口,其中包含一些较小的NSView对象,每个对象包含几个不同的控件,标签,图像等。其中一个视图(及其包含的所有内容)在响应给定标志时被禁用。设置该标志后,我会自动禁用并灰显该NSView中嵌入的所有控件。
Question: I would like to know how to darken the disabled NSView
. The effect I am looking for would be something like drawing a 50% transparent black box on top of the disabled NSView
. The background and all of the controls would still be visible, but the colors would be a darker shade. Is there a simple way to do this?
问题:我想知道如何使禁用的NSView变暗。我正在寻找的效果就像在禁用的NSView上绘制一个50%透明的黑盒子。背景和所有控件仍然可见,但颜色会更暗。有一个简单的方法吗?
1 个解决方案
#1
CoreAnimation in 10.5 should provide an easy way to put a translucent layer above a view. You can create a black layer in front of the view, with the opacity at 0%. When you want to darken the view, set the opacity of the black layer to 50%, and the view will be darkened smoothly.
10.5中的CoreAnimation应该提供一种将半透明层放在视图上方的简单方法。您可以在视图前面创建一个黑色图层,不透明度为0%。如果要使视图变暗,请将黑色图层的不透明度设置为50%,并且视图将平滑地变暗。
#1
CoreAnimation in 10.5 should provide an easy way to put a translucent layer above a view. You can create a black layer in front of the view, with the opacity at 0%. When you want to darken the view, set the opacity of the black layer to 50%, and the view will be darkened smoothly.
10.5中的CoreAnimation应该提供一种将半透明层放在视图上方的简单方法。您可以在视图前面创建一个黑色图层,不透明度为0%。如果要使视图变暗,请将黑色图层的不透明度设置为50%,并且视图将平滑地变暗。