有人能给出一个将模糊应用于图像的小例子吗?我已经尝试了很长一段时间了:(在obj仍然是新的!)
UIVisualEffectView为复杂的视觉效果提供了一个简单的抽象。根据所期望的效果,结果可能会影响视图后面的分层内容或添加到视图的contentView中的内容。 将UIVisualEffectView应用于现有视图,将模糊或振动效果应用于现有视图。将UIVisualEffectView添加到视图层次结构后,将所有子视图添加到UIVisualEffectView的contentView中。不要将子视图直接添加到UIVisualEffectView本身。
发布于 2014-06-06 14:02:54
把这个模糊的视图放到imageView上就行了。以下是目标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)发布于 2014-06-14 23:33:06
下面是如何将UIVibrancyEffect和UIBlurEffect与UIVisualEffectView结合使用
目标-C:
// Blur effect
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
[blurEffectView setFrame:self.view.bounds];
[self.view addSubview:blurEffectView];
// Vibrancy effect
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];
UIVisualEffectView *vibrancyEffectView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
[vibrancyEffectView setFrame:self.view.bounds];
// Label for vibrant text
UILabel *vibrantLabel = [[UILabel alloc] init];
[vibrantLabel setText:@"Vibrant"];
[vibrantLabel setFont:[UIFont systemFontOfSize:72.0f]];
[vibrantLabel sizeToFit];
[vibrantLabel setCenter: self.view.center];
// Add label to the vibrancy view
[[vibrancyEffectView contentView] addSubview:vibrantLabel];
// Add the vibrancy view to the blur view
[[blurEffectView contentView] addSubview:vibrancyEffectView];斯威夫特
// Blur Effect
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
view.addSubview(blurEffectView)
// Vibrancy Effect
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
vibrancyEffectView.frame = view.bounds
// Label for vibrant text
let vibrantLabel = UILabel()
vibrantLabel.text = "Vibrant"
vibrantLabel.font = UIFont.systemFont(ofSize: 72.0)
vibrantLabel.sizeToFit()
vibrantLabel.center = view.center
// Add label to the vibrancy view
vibrancyEffectView.contentView.addSubview(vibrantLabel)
// Add the vibrancy view to the blur view
blurEffectView.contentView.addSubview(vibrancyEffectView)发布于 2014-08-18 19:16:59
您还可以使用接口生成器轻松地在简单的情况下创建这些效果。由于视图的z值将取决于它们在文档大纲中列出的顺序,因此可以在要模糊的视图之前将UIVisualEffectView拖到文档大纲上。这将自动创建嵌套的UIView,它是给定UIVisualEffectView的contentView属性。嵌套在这个视图中,你想要出现在模糊的顶部。

您还可以轻松地利用振动UIVisualEffect,它将在文档大纲中自动创建另一个嵌套的UIVisualEffectView,默认启用振动。然后,您可以向嵌套的UIView添加一个标签或文本视图(同样是UIVisualEffectView的contentView属性),以达到与">幻灯片解锁“UI元素相同的效果。

https://stackoverflow.com/questions/24067719
复制相似问题