在OS X Yosemite中,苹果引入了一个新的类NSVisualEffectView。目前,这个类还没有文档,但是我们可以在Interface Builder中使用它。
如何在窗口标题栏中使用NSVisualEffectView?
下面是一个例子:在Safari中,当你滚动时,内容会出现在工具栏和标题栏下面,并带有振动和模糊的效果。

发布于 2014-06-27 12:40:36
@sgonzalez的回答迫使我去探索我找到titlebarAppearsTransparent属性的NSWindow.h文件。
所以我们得到:
class BluredWindow: NSWindow {
override func awakeFromNib() {
let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 300, 180))
visualEffectView.material = NSVisualEffectView.Material.dark
visualEffectView.blendingMode = NSVisualEffectView.BlendingMode.behindWindow
visualEffectView.state = NSVisualEffectView.State.active
self.styleMask = self.styleMask | NSFullSizeContentViewWindowMask
self.titlebarAppearsTransparent = true
//self.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
self.contentView.addSubview(visualEffectView)
self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[visualEffectView]-0-|",
options: NSLayoutConstraint.FormatOptions.directionLeadingToTrailing,
metrics: nil,
views: ["visualEffectView":visualEffectView]))
self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[visualEffectView]-0-|",
options: NSLayoutConstraint.FormatOptions.directionLeadingToTrailing,
metrics: nil,
views: ["visualEffectView":visualEffectView]))你也可以在IB中设置NSVisualEffectView,它将在标题栏上展开。
发布于 2014-06-27 04:31:47
您需要修改窗口的样式掩码以包含NSFullSizeContentViewWindowMask,以便其内容视图可以“溢出”到其中。
您可以通过将以下行添加到您的AppDelegate来轻松完成此操作:
self.window.styleMask = self.window.styleMask | NSFullSizeContentViewWindowMask;如果您希望它显示为黑色,就像在FaceTime中一样,您还需要添加下面这行代码:
self.window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)发布于 2016-01-24 16:16:08
带示例的分步教程:
http://eon.codes/blog/2016/01/23/Chromeless-window/
设置半透明:
NSFullSizeContentViewWindowMask (以便半透明效果也将在标题栏区域可见,保留此项,标题栏区域将为空)self.titlebarAppearsTransparent = true (隐藏标题栏默认图形)<代码>G210
。
let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 0, 0))//<---the width and height is set to 0, as this doesn't matter.
visualEffectView.material = NSVisualEffectMaterial.AppearanceBased//Dark,MediumLight,PopOver,UltraDark,AppearanceBased,Titlebar,Menu
visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow//I think if you set this to WithinWindow you get the effect safari has in its TitleBar. It should have an Opaque background behind it or else it will not work well
visualEffectView.state = NSVisualEffectState.Active//FollowsWindowActiveState,Inactive
self.contentView = visualEffectView/*you can also add the visualEffectView to the contentview, just add some width and height to the visualEffectView, you also need to flip the view if you like to work from TopLeft, do this through subclassing*/

还允许您创建半透明的无铬窗口:

https://stackoverflow.com/questions/24414483
复制相似问题