如何在视图顶部添加模糊视图? [英] How to add a blurred view ontop of a view?

查看:182
本文介绍了如何在视图顶部添加模糊视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSTableView重新加载。在加载新数据时,我想使用旋转器在其顶部添加子视图。我希望顶上的视图是半透明的,并揭示它下面的视图,模糊。

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?

推荐答案

最简单的解决方案比 -bitmapImageRepEtc :一个,比光栅化缩放方法更适用于Mac OS - 是将重叠视图设置为使用核心动画背景层,然后为该图层提供核心图像模糊过滤器。这是一种在Mac OS中使用的技术,从Dock菜单到菜单栏本身。 Interface Builder让它轻松设置,但你也可以在代码中这样做:

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

这篇关于如何在视图顶部添加模糊视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆