How can I darken everything displayed in a single NSView?

时间秒杀一切 提交于 2020-01-04 02:33:09

问题


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.

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?


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



来源:https://stackoverflow.com/questions/466249/how-can-i-darken-everything-displayed-in-a-single-nsview

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