创建自定义模糊视图 [英] Create a custom blur view

查看:76
本文介绍了创建自定义模糊视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用中添加模糊视图.

I need to add a blur view to my app.

我已经尝试过 UIBlurEffect ,但是只有3个选项(亮,暗,ExtraLight),并且我需要在亮与暗之间添加一些东西.

I've tried UIBlurEffect but there are just 3 option (Light, Dark, ExtraLight), and I need something between Light and Dark.

我了解我唯一的选择是创建自定义模糊视图,但是我该怎么做?

I understood the only option I have is to create a custom blur view, but how can I do that?

有什么主意吗?

推荐答案

如果您使用的是故事板,这是一种简单的解决方法.首先,您需要在情节提要的右上方添加一个"具有模糊效果的视觉效果视图",在该位置可以看到您的图像,UIUiew或uielement.现在,如下所示绘制视觉效果视图的出口:-

Here is an easy way out if you are using a storyboard. First you need to add a "Visual Effect View with Blur" from storyboard right above where your image,UIUiew or uielement is to be seen. Now draw the outlet of the Visual effect view as follows:-

 @IBOutlet weak var blurredViewVisulaEffect: UIVisualEffectView!

并将这两行添加到viewDidLoad方法中

and add these two lines in the viewDidLoad method

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
blurredViewVisulaEffect.effect = blurEffect

根据我们的要求操纵视图:-现在,如果要自定义图像的模糊度,请从情节提要中更改UIVisualEffectView的alpha值.将 Alpha 的值保持在0.5到0.8之间以获得所需的模糊度.而且,如果您要更改视图的阴影/颜色(如您在浅色和深色之间提到的那样),则需要将UIVisualEffectView的背景色设置为黑色,并将其不透明性从100%更改为30%(或根据需要可以是40%).

MANIPULATION of the view to make it according to our requirement:- Now if you want to customise the blurriness of the image, then change the value of alpha of UIVisualEffectView from storyboard.Keep the value of Alpha within 0.5 to 0.8 to obtain desired blurriness. And if you want to change the shade/color of the view, as mentioned by you between light and dark then you need to set the background color of your UIVisualEffectView to black and change its opacity from 100% to 30%(or may be 40 as required).

这篇关于创建自定义模糊视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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