iOS 7 动态模糊效果,如控制中心 [英] iOS 7 dynamic blur effect like in Control Center

查看:26
本文介绍了iOS 7 动态模糊效果,如控制中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个类似于 iOS7 中的控制中心的控制器.从 WWDC session #226 我已经学会了如何获得具有不同效果的模糊图像

I'm trying to make a controller that will be similar to Control Center in iOS7. From WWDC session #226 I've learnt how to get blurred image with different effects

UIGraphicsBeginImageContextWithOptions(image.size, NULL, 0);

[view drawViewHierarchyInRect:rect];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

lightImage = [newImage applyLightEffect];

所以,换句话说,我们只是捕捉一些图像(制作屏幕截图),执行模糊效果并根据我们的需要使用这个模糊图像.

So, in other words, we just capture some image (make screenshot), perform blur effect and use this blurred image for our needs.

但是,如果您在一些动态内容上方打开控制中心,您会注意到控制中心的模糊背景和内容一样正在发生变化.

But if you open control center above some dynamic content you'll notice that control center's blurred background is changing as well as content does.

有人知道如何复制这种行为吗?

Does anybody know how to replicate this behavior?

我看到它的唯一方法是捕捉内容并以一定的间隔(例如半秒)制作模糊效果.但它看起来多余.

The only way I see it is to capture content and make blur effect with some interval (e.g. half a second). But it looks redundantly.

推荐答案

以下是我找到的现成解决方案:

Here are ready solutions that I've found:

1.最意想不到的:使用UIToolBar

- (id) initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame]))
    {
        [self setup];
    }
    return self;
}

- (id) initWithCoder:(NSCoder *)coder
{
    if ((self = [super initWithCoder:coder]))
    {
        [self setup];
    }
    return self;
}

- (void) setup
{
    if (iOS7OrLater)
    {
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];

        UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:self.bounds];
        toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        toolbar.barTintColor = self.tintColor;
        [self insertSubview:toolbar atIndex:0];
    }
}

UIToolbar 可以满足这个需求,因为它有他唯一的内置模糊机制,而且这个机制是动态的,有什么好处.但不好的是,由于某种原因,它忽略了颜色并使背景看起来无可救药......

UIToolbar can be used for this needs, bacuse it has his only build-in blur mechanism, and this mechanism is dynamic, what is good. But the bad thing is that in some reason it ignores colors and makes background looks irredeemably...

更新:

为避免断色,请勿使用 barTintColor.如果您想要深色样式的模糊,您也可以更改工具栏的样式(使用 UIBarStyleBlack).

To avoid color breaking, do not use barTintColor. You also may change style of toolbar if you want dark styled blur (use UIBarStyleBlack).

2.FXBlurView.

2. FXBlurView.

与工具栏不同,它更积极,但它的动态机制很少见,实际上它只能用于静态背景.(动态 = 否).

Unlike toolbar it more positive, but it's dynamic mechanism is rare yet and in fact it can be used only for static background. (dynamic = NO).

这篇关于iOS 7 动态模糊效果,如控制中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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