如何使一个NSView中显示的所有内容变暗? [英] How can I darken everything displayed in a single NSView?
问题描述
背景:我的应用程序有一个主窗口,其中包含一些较小的 NSView
对象,每个对象包含几个不同的控件,等等。响应给定的标志,禁用这些视图之一(及其包含的一切)。当设置标志时,我会自动禁用并隐藏 NSView
中嵌入的所有控件。
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
上绘制一个50%透明的黑盒子。背景和所有的控件仍然可见,但颜色将是一个更暗的阴影。有没有一个简单的方法来做这个?
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?
推荐答案
10.5中的CoreAnimation应该提供一个简单的方法, 。您可以在视图前创建一个黑色层,不透明度为0%。当您想使视图变暗时,将黑色层的不透明度设置为50%,视图将平滑变暗。
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.
这篇关于如何使一个NSView中显示的所有内容变暗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!