对NSWindow的内容进行灰色处理。

时间:2023-01-24 08:55:08

I have an NSWindow with 2 NSViews (an NSSplitView and a custom NSView). Accessing the data to populate these views can take some time. During this period, I'd like to gray out the content of these views.

我有一个带有两个NSView的NSWindow(一个NSSplitView和一个定制的NSView)。访问数据以填充这些视图需要一些时间。在这段时间里,我想把这些观点的内容变灰。

My first approach was to have a black third NSView that covered the other 2 and achieve the graying out effect by changing its alpha value. However I've since learned having a hierarchy with sibling views is undefined.

我的第一个方法是有一个黑色的第三个NSView,它覆盖了另外两个,通过改变alpha值来实现灰色效果。然而,我已经学会了拥有一个带有兄弟姐妹视图的层次结构是没有定义的。

What is the best approach here?

这里最好的方法是什么?

  • Cache the NSBitmapImageRep of the 2 views, then replace them with the 3rd view, using the cached image(s) as background
  • 缓存两个视图的NSBitmapImageRep,然后用第三个视图替换它们,使用缓存的图像作为背景。
  • Set the alpha value for each view separately (still not quite sure how to get the black background for the graying effect)
  • 分别设置每个视图的alpha值(仍然不确定如何获得灰色效果的黑色背景)
  • Something I haven't considered
  • 我还没有考虑

2 个解决方案

#1


6  

I'd use a child window. Set its content view to a plain black view (hopefully with status and progress information in subviews), and its alpha value to the desired fade-out, and add it as a child window of the window whose content you want to fade out.

我将使用子窗口。将其内容视图设置为纯黑色视图(希望在子视图中有状态和进度信息),并将其alpha值设置为所期望的淡出效果,并将其添加为窗口的子窗口,其内容您希望淡出。

#2


2  

I'd teach the views how to draw themselves in a disabled state, but there are other suggestions here:

我将教大家如何把自己画在一个残疾的国家里,但是这里还有其他的建议:

How can I darken everything displayed in a single NSView?

我怎样才能把所有显示在一个NSView中的东西都变黑?

#1


6  

I'd use a child window. Set its content view to a plain black view (hopefully with status and progress information in subviews), and its alpha value to the desired fade-out, and add it as a child window of the window whose content you want to fade out.

我将使用子窗口。将其内容视图设置为纯黑色视图(希望在子视图中有状态和进度信息),并将其alpha值设置为所期望的淡出效果,并将其添加为窗口的子窗口,其内容您希望淡出。

#2


2  

I'd teach the views how to draw themselves in a disabled state, but there are other suggestions here:

我将教大家如何把自己画在一个残疾的国家里,但是这里还有其他的建议:

How can I darken everything displayed in a single NSView?

我怎样才能把所有显示在一个NSView中的东西都变黑?