Adjust the blur radius and transparency of NSVisualEffectView

Can I adjust the blur radius and transparency of NSVisualEffectView when it is applied to NSWindow (Swift or Objective-C)? I tried all variations of NSVisualEffectMaterial (dark, medium, light), but it doesn’t cut it. In the image below, I used the non-public Apple API with CGSSetWindowBackgroundBlurRadius on the left and NSVisualEffectView on the right.

enter image description here

I am trying to achieve what is on the left, but it seems that I am rejected to use legal methods.

Here is my code:

 blurView.blendingMode = NSVisualEffectBlendingMode.BehindWindow blurView.material = NSVisualEffectMaterial.Medium blurView.state = NSVisualEffectState.Active self.window!.contentView!.addSubview(blurView) 

Perhaps related - but does not answer my question:

+5
source share
1 answer

Although I would not recommend this if you are not ready to return to it without working in a future version, you can subclass NSVisualEffectView to do the following:

 - (void)updateLayer { [super updateLayer]; [CATransaction begin]; [CATransaction setDisableActions:YES]; CALayer *backdropLayer = self.layer.sublayers.firstObject; if ([backdropLayer.name hasPrefix:@"kCUIVariantMac"]) { for (CALayer *activeLayer in backdropLayer.sublayers) { if ([activeLayer.name isEqualToString:@"Active"]) { for (CALayer *sublayer in activeLayer.sublayers) { if ([sublayer.name isEqualToString:@"Backdrop"]) { for (id filter in sublayer.filters) { if ([filter respondsToSelector:@selector(name)] && [[filter name] isEqualToString:@"blur"]) { if ([filter respondsToSelector:@selector(setValue:forKey:)]) { [filter setValue:@5 forKey:@"inputRadius"]; } } } } } } } } [CATransaction commit]; } 

Although this does not use the Private API as such, it begins to delve into the hierarchy of layers that you don’t have, so be sure to double check that what you return is what you expect and unsuccessfully elegant, if not, For example , on 10.10 Yosemite, the Backdrop layer was a direct decade in the Visual Effect view, so this could change in the future.

+2
source

All Articles