我想要一个具有半透明模糊背景的窗口,就像终端可以做的那样。请观看这段大约 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]];
有什么提示或示例可以帮助我完成我想做的事情吗? 谢谢!
最佳答案
不需要图层和滤镜,NSWindow 自己就能搞定
[mywindow setOpaque:NO];
[mywindow setBackgroundColor: [NSColor colorWithCalibratedHue:0.0 saturation:0.0 brightness:0.2 alpha:0.5]];
请不要使用它,因为它也会使您的标题栏变为 alpha(将其发布到此处以防其他人需要)
[mywindow setOpaque:NO];
[mywindow setBackgroundColor: [NSColor blackColor]];
[mywindow setAlphaValue:0.5];
关于macos - 如何获得半透明模糊背景的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11174918/