How to add a blurred view ontop of a view?

后端 未结 4 1243
灰色年华
灰色年华 2021-01-30 09:54

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 r

4条回答
  •  时光说笑
    2021-01-30 10:24

    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];
    

提交回复
热议问题