Cocoa NSView blurred background

不问归期 提交于 2019-12-07 19:21:19

问题


I know it's possible to create transparent windows in Cocoa, although is it possible to blur whatever is behind it? I know there's been similar questions, but they deal more blurring what is within the actual NSView, not what is behind it. Is this even possible, and If so what method would I need to look into?

Possible                      Impossible?

回答1:


In order to answer you, yes its Possible.

If you want that effect, check out this GitHub Project I created. I subclassed NSWindow in order to disable opacity and then I added a Background Filter:Gaussian Blur to the NSView using the View Effects Inspector located at the Xcode Utilities Side Bar (you can change the radius value for more or less blur effect).

If you want the new Yosemite View effect, check out the new class they released NSVisualEffectView, just subclass the NSView you want to use this effect.

Hope you find my answer useful.

Best regards,




回答2:


My contribution as I wanted to set the radius and the color.

Doing it in a custom view to blur what is behind. HTH

view.wantsLayer = true
view.layerUsesCoreImageFilters = true
view.layer?.backgroundColor = NSColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 0.5).CGColor

let blurFilter = CIFilter(name: "CIGaussianBlur")
blurFilter?.setDefaults()
blurFilter?.setValue(2.5, forKey: kCIInputRadiusKey)
view.layer?.backgroundFilters?.append(blurFilter!)


来源:https://stackoverflow.com/questions/23821693/cocoa-nsview-blurred-background

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