我正在尝试制作一个类似于iOS7中的控制中心的控制器。从WWDC会议#226中,我学会了如何获得具有不同效果的模糊图像
UIGraphicsBeginImageContextWithOptions(image.size, NULL, 0);
[view drawViewHierarchyInRect:rect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lightImage = [newImage applyLightEffect];因此,换句话说,我们只需要捕获一些图像(制作屏幕截图),执行模糊效果,并根据需要使用这些模糊图像。
但是如果你打开控制中心上面的一些动态内容,你会注意到控制中心的模糊背景正在改变,就像内容一样。
有人知道如何复制这种行为吗?
我看到它的唯一方式是捕获内容,并以一定的间隔(例如半秒)实现模糊效果。但它看起来是多余的。
发布于 2013-09-12 23:52:37
以下是我找到的现成解决方案:
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可以用于这种需求,因为它有他唯一的内置模糊机制,并且这个机制是动态的,什么是好的。但糟糕的是,由于某种原因,它忽略了颜色,使背景看起来不可挽回地……

更新:
为避免颜色损坏,请不要使用barTintColor。你也可以改变工具栏的风格,如果你想要深色风格的模糊(使用UIBarStyleBlack)。
2. .
与工具栏不同,它更积极,但它的动态机制还很少见,实际上它只能用于静态背景。(动态=否)。

发布于 2014-06-05 20:46:26
在iOS8中,我们可以使用UIVisualEffect类来实现视图的模糊效果。
发布于 2015-01-05 19:30:28
你可以使用下面的代码在视图上应用模糊效果。
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = MYview.bounds;
[MYview addSubview:visualEffectView];https://stackoverflow.com/questions/17704240
复制相似问题