问题描述
背景:我的应用程序有一个主窗口,其中包含几个较小的 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 中显示的所有内容变暗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!