本文介绍了如何使用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应用于现有视图以应用模糊或 充满活力的效果给现有的视图.添加完之后 将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

推荐答案

只需将此模糊视图放在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];

和Swift:

var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))

visualEffectView.frame = imageView.bounds

imageView.addSubview(visualEffectView)

这篇关于如何使用UIVisualEffectView来模糊图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 08:23