【发布时间】:2012-06-25 20:34:50
【问题描述】:
我想要一个具有半透明模糊背景的窗口,就像终端可以做的那样。观看此视频,大约 30 秒,了解我的意思:http://www.youtube.com/watch?v=zo8KPRY6-Mk
在此处查看图片:http://osxdaily.com/wp-content/uploads/2011/04/mac-os-x-lion-terminal.jpg
我已经在谷歌上搜索了一个小时,但找不到任何工作。我相信我需要以某种方式创建一个核心动画层并添加一个背景过滤器,但到目前为止我一直没有成功......我只看到我的窗口的灰色背景。这是我目前得到的代码:
代码:
// Get the content view -- everything but the titlebar.
NSView *theView = [[self window] contentView];
[theView setAlphaValue:0.5];
// Create core animation layer, with filter
CALayer *backgroundLayer = [CALayer layer];
[theView setWantsLayer:YES];
[theView setLayer:backgroundLayer];
CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[blurFilter setDefaults];
[theView layer].backgroundFilters = [NSArray arrayWithObject:blurFilter];
[[theView layer] setBackgroundFilters:[NSArray arrayWithObject:blurFilter]];
有任何提示或示例来做我想做的事吗? 谢谢!
【问题讨论】:
-
你正在寻找一个叫做HUD窗口的东西!尝试在谷歌上搜索它会帮助你
-
谢谢,但我仍然没有得到太多。找到了几篇有前途的论坛帖子,但指出了不再存在的示例或博客帖子。
-
坦率地说,我怀疑没有私有 API 很容易实现模糊。例如。 stackoverflow.com/questions/5901135/…
-
在最新版本的 OSX/Xcode 中有一个可行的解决方案:stackoverflow.com/questions/41475551/…
标签: macos cocoa calayer nswindow