Nas*_*ban 35 iphone objective-c blur ios7
我正在尝试制作一个与iOS7中的Control Center类似的控制器.从WWDC会议#226我已经学会了如何使用不同的效果获得模糊的图像
UIGraphicsBeginImageContextWithOptions(image.size, NULL, 0);
[view drawViewHierarchyInRect:rect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lightImage = [newImage applyLightEffect];
Run Code Online (Sandbox Code Playgroud)
因此,换句话说,我们只捕获一些图像(制作屏幕截图),执行模糊效果并根据我们的需要使用此模糊图像.
但是如果你在一些动态内容之上打开控制中心,你会注意到控制中心模糊的背景和内容都在变化.
有人知道如何复制这种行为吗?
我看到它的唯一方法是捕捉内容并以一定间隔(例如半秒)制作模糊效果.但它看起来多余.
Nas*_*ban 43
以下是我发现的现成解决方案:
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];
}
}
Run Code Online (Sandbox Code Playgroud)
UIToolbar可以用于满足这种需求,因为它具有唯一的内置模糊机制,而且这种机制是动态的,有什么好处.但糟糕的是,在某种程度上它忽略了颜色并使背景看起来不可救药......

更新:
为避免颜色中断,请勿使用barTintColor.如果你想要暗色调模糊,你也可以改变工具栏的样式(使用UIBarStyleBlack).
2. FXBlurView.
与工具栏不同,它更积极,但它的动态机制很少,实际上它只能用于静态背景.(动态= NO).

您可以使用下面的代码在视图上应用模糊效果.
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = MYview.bounds;
[MYview addSubview:visualEffectView];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34505 次 |
| 最近记录: |