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

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

问题描述

我正在尝试制作一个与iOS7中的Control Center类似的控制器。从WWDC会议#226我学会了如何使用不同的效果来模糊图像

  UIGraphicsBeginImageContextWithOptions(image.size,NULL,0 ); 

[查看drawViewHierarchyInRect:rect];

UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

lightImage = [newImage applyLightEffect];

因此,换句话说,我们只捕获一些图像(制作屏幕截图),执行模糊效果并使用这个模糊的图像满足了我们的需求。



但是如果你打开一些动态内容上方的控制中心,你会发现控制中心模糊的背景和内容都在变化。 / p>

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



我看到的唯一方法是捕获内容并制作模糊效果与某个间隔(例如半秒)。但它看起来多余。

解决方案

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



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

   - (id)initWithFrame:(CGRect)frame 
{
if((self = [super initWithFrame:frame]))
{
[self setup];
}
返回自我;
}

- (id)initWithCoder:(NSCoder *)编码器
{
if((self = [super initWithCoder:coder]))
{
[自我设置];
}
返回自我;
}

- (无效)设置
{
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可以满足这种需求他唯一的内置模糊机制,这种机制是动态的,有什么好处。但糟糕的是,在某种程度上它会忽略颜色并使背景看起来不可救药......





更新:



为避免颜色中断,请勿使用barTintColor。如果你想要暗色调模糊,你也可以改变工具栏的样式(使用UIBarStyleBlack)。



2。 FXBlurView



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




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. The most unexpected: Use 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 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...

Update:

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.

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天全站免登陆