我试图复制苹果公开发布的iOS 7示例屏幕上的模糊背景:

这个问题建议对下面的内容应用CI过滤器,但这是一个完全不同的方法。很明显,iOS 7并没有捕捉到下面视图的内容,原因有很多:

做一些粗略的测试,截取以下视图的截图,并应用CIGaussianBlur过滤器,使用足够大的半径来模拟iOS 7的模糊风格,即使在模拟器上也需要1-2秒。 iOS 7的模糊视图能够模糊动态视图,比如视频或动画,没有明显的延迟。

有没有人可以假设他们可以使用什么框架来创建这种效果,以及是否有可能使用当前的公共api创建类似的效果?

编辑:(来自评论)我们不知道苹果是怎么做的,但我们能做出一些基本的假设吗?我们可以假设他们在使用硬件,对吧?

效果是否在每个视图中都是自包含的,以至于效果实际上不知道它背后是什么?或者,基于模糊的工作原理,模糊背后的内容必须被考虑进去?

如果效果背后的内容是相关的,我们是否可以假设苹果正在接收以下内容的“feed”,并不断地以模糊的方式渲染它们?


当前回答

iOS8回答了这些问题。

- (instancetype)initWithEffect:(UIVisualEffect *)effect

或迅速:

初始化(效果效果:UIVisualEffect)

其他回答

为什么要麻烦地复制这种效果呢?在你的视图后面画一个UIToolbar。

myView.backgroundColor = [UIColor clearColor];
UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:myView.frame];
bgToolbar.barStyle = UIBarStyleDefault;
[myView.superview insertSubview:bgToolbar belowSubview:myView];

这里有一个非常简单的方法:https://github.com/JagCesar/iOS-blur

只要复制UIToolbar的图层就完成了,AMBlurView为你做了。 好吧,它没有控制中心那么模糊,但已经足够模糊了。

记住,iOS7是保密协议。

Apple released code at WWDC as a category on UIImage that includes this functionality, if you have a developer account you can grab the UIImage category (and the rest of the sample code) by going to this link: https://developer.apple.com/wwdc/schedule/ and browsing for section 226 and clicking on details. I haven't played around with it yet but I think the effect will be a lot slower on iOS 6, there are some enhancements to iOS 7 that make grabbing the initial screen shot that is used as input to the blur a lot faster.

直接链接:https://developer.apple.com/downloads/download.action?path=wwdc_2013/wwdc_2013_sample_code/ios_uiimageeffects.zip

你可以从苹果的DEMO中找到你的解决方案: WWDC 2013,找到并下载UIImageEffects示例代码。

然后是@Jeremy Fox的代码。我把它改成

- (UIImage*)getDarkBlurredImageWithTargetView:(UIView *)targetView
{
    CGSize size = targetView.frame.size;

    UIGraphicsBeginImageContext(size);
    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(c, 0, 0);
    [targetView.layer renderInContext:c]; // view is the view you are grabbing the screen shot of. The view that is to be blurred.
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return [image applyDarkEffect];
}

希望这对你有所帮助。

我写了UIView的子类它能在任何自定义视图上产生原生ios7模糊。它使用UIToolbar,但以一种安全的方式改变它的帧,边界,颜色和alpha实时动画。

如果你发现任何问题请告诉我。

https://github.com/ivoleko/ILTranslucentView