NSWindow动画模糊&使用CATransition和CIFilter淡化:第一次不工作?

时间:2016-08-23 20:14:00

标签: cocoa calayer nswindow cifilter catransition

我尝试对NSWindow应用模糊+饱和度+淡化效果。基本上,当打开一张纸时,我希望模态纸后面的窗口首先变得模糊。

奇怪的是,我可以实现这一点,但总是在第二个动画中,而不是第一个。我尝试了addSubview&的各种组合。 addAnimation等,但到目前为止总是失败。

有什么想法吗?这是我的代码:

self.contentView!.wantsLayer = true
let animation = CATransition()
animation.type = kCATransitionFade
animation.duration = 0.5

self.contentView!.layer?.addAnimation(animation, forKey: "layerAnimation")

let saturationFilter = CIFilter(name: "CIColorControls")!
saturationFilter.setDefaults()
saturationFilter.setValue(2, forKey: "inputSaturation")

let blurFilter = CIFilter(name: "CIGaussianBlur")!
blurFilter.setDefaults()
blurFilter.setValue(1.5, forKey:"inputRadius")

let coverView = NSView()
coverView.frame = self.contentView!.bounds
coverView.wantsLayer = true
coverView.layerUsesCoreImageFilters = true
coverView.autoresizingMask = [.ViewWidthSizable, .ViewHeightSizable]
coverView.layer!.opaque = false

coverView.layer!.backgroundColor = NSColor(white: 0.9, alpha: 0.5).CGColor
coverView.layer!.backgroundFilters = [saturationFilter, blurFilter]

self.contentView!.addSubview(coverView)

0 个答案:

没有答案