Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a blurred view ontop of a view?

I have an NSTableView that gets reloaded. While new data is loading, I want to add a subview ontop of it with a spinner. I would like the view ontop to be semi-transparent and reveal the view beneath it, to be blurred. How would I go about doing this?

like image 465
Sheehan Alam Avatar asked Mar 09 '11 13:03

Sheehan Alam


1 Answers

The easiest solution—significantly more so than the -bitmapImageRepEtc: one, and more applicable to Mac OS than the rasterization-scale method—is to set your overlay view to use a Core Animation backing layer, then give that layer a Core Image blur filter. It's a technique used all over the Mac OS, from the Dock menus to the menu bar itself. Interface Builder makes it trivially easy to set up, but you can do it in code as well, like this:

CALayer *backgroundLayer = [CALayer layer];
[backgroundView setLayer:backgroundLayer];
[backgroundView setWantsLayer:YES];

CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[blurFilter setDefaults];

[backgroundView layer].backgroundFilters = [NSArray arrayWithObject:blurFilter];
like image 83
Noah Witherspoon Avatar answered Sep 21 '22 06:09

Noah Witherspoon