如何使用UIVisualEffectView? [英] How to use 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
提供了对复杂的
视觉效果的简单抽象。根据所需的效果,结果可能
影响视图后面的内容或添加到视图$ b $的内容b contentView。
The
UIVisualEffectView
provides 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.
推荐答案
只需将此模糊视图放在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!