How to use UIVisualEffectView to Blur Image?(如何使用 UIVisualEffectView 模糊图像?)
问题描述
有人可以举一个将模糊应用于图像的小例子吗?我一直在尝试找出代码有一段时间了 :( 在 obj c 还是新的!
Could someone give a small example of applying the blur to an image? I've been trying to figure out the code for a while now :( still new at obj c!
UIVisualEffectView 提供了对复杂的简单抽象视觉效果.根据所需的效果,结果可能影响视图后面的内容或添加到视图的内容内容视图.
The
UIVisualEffectViewprovides a simple abstraction over complex visual effects. Depending on the desired effect, the results may affect content layered behind the view or content added to the view’s contentView.
将 UIVisualEffectView 应用到现有视图以应用模糊或现有视图的活力效果.添加后UIVisualEffectView 到视图层次结构中,将任何子视图添加到UIVisualEffectView 的 contentView.不要直接添加子视图UIVisualEffectView 本身.
Apply a UIVisualEffectView to an existing view to apply a blur or
vibrancy effect to the exiting view. After you add the
UIVisualEffectView to the view hierarchy, add any subviews to the
contentView of the UIVisualEffectView. Do not add subviews directly to
the UIVisualEffectView itself.
https://developer.apple.com/documentation/uikit/uivisualeffectview#//apple_ref/occ/instp/UIVisualEffectView/contentView
推荐答案
只要把这个blur view放到imageView上就行了.下面是 Objective-C 中的一个例子:
Just put this blur view on the imageView. Here is an example in Objective-C:
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = imageView.bounds;
[imageView addSubview:visualEffectView];
和斯威夫特:
var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
visualEffectView.frame = imageView.bounds
imageView.addSubview(visualEffectView)
这篇关于如何使用 UIVisualEffectView 模糊图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 UIVisualEffectView 模糊图像?
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
