问题描述
有人可以举一个将模糊应用于图像的小例子吗?我已经尝试了一段时间了:((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.
推荐答案
只需将此模糊视图放在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来模糊图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!