创建一个模糊的覆盖层视图

399
在新的iOS音乐应用中,我们可以看到一个模糊了的视图后面是一个专辑封面。如何实现这样的效果呢?我已经阅读了文档,但没有找到相关内容。
25个回答

0

您可以直接使用“Visual Effect View with Blur”和“Visual Effect View with Blur and Vibrancy”来制作背景模糊。

iOS应用程序中制作模糊背景的步骤如下:

  1. 在对象库中搜索“Visual Effect View with Blur”

步骤1图像

  1. 将“Visual Effect View with Blur”拖到Storyboard中并进行设置...

步骤2图像

  1. 最后...您就可以制作应用程序背景模糊了!

点击任何按钮之前的应用程序布局!

单击使整个应用程序背景模糊的按钮后的应用程序视图!


0

苹果公司为UIImage类提供了一个名为UIImage+ImageEffects.h的扩展。在这个类中,您可以使用所需的方法来模糊您的视图。


1
你能分享更多关于这些方法的信息吗? - Mike Laren
请查看此处:https://developer.apple.com/library/ios/samplecode/UIImageEffects/Listings/UIImageEffects_main_m.html - Brian Sachetta

-1

如果为tableView添加一个深色模糊视图,这会让它看起来非常美观:

tableView.backgroundColor = .clear
let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = tableView.bounds
blurEffectView.autoresizingMask = [.flexibleHeight, .flexibleWidth]


// Assigning blurEffectView to backgroundView instead of addSubview to tableView makes tableView cell not blocked by blurEffectView 
tableView.backgroundView = blurEffectView

-2

Swift 4:

要添加覆盖层或弹出视图,您还可以使用容器视图,从中获取免费的视图控制器(您可以从常规对象调色板/库中获取容器视图)

步骤:

有一个视图(图片中的ViewForContainer),它包含此容器视图,在显示容器视图的内容时将其变暗。在第一个视图控制器内连接插座。

当第一个视图控制器加载时隐藏此视图

单击按钮时取消隐藏,输入图像描述

要在显示容器视图内容时使此视图变暗,请将视图背景设置为黑色,不透明度设置为30%

我已经在其他Stackoverflow问题中添加了关于popview视图创建的答案 https://dev59.com/-GQo5IYBdhLWcg3wOdFZ#49729431


-3
简单的答案是添加一个子视图并更改其透明度。
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
UIView *subView = [[UIView alloc] initWithFrame:popupView.frame];
UIColor * backImgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_Img.png"]];
subView.backgroundColor = backImgColor;
subView.alpha = 0.5;
[mainView addSubview:subView];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接