Graying out an NSWindow's content

可紊 提交于 2019-12-07 16:31:13

问题


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.

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.

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
  • Set the alpha value for each view separately (still not quite sure how to get the black background for the graying effect)
  • Something I haven't considered

回答1:


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.




回答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?



来源:https://stackoverflow.com/questions/1656049/graying-out-an-nswindows-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!