如何淡入和淡出UIVisualEffectView和/或UIBlurEffect? [英] How to fade a UIVisualEffectView and/or UIBlurEffect in and out?

查看:823
本文介绍了如何淡入和淡出UIVisualEffectView和/或UIBlurEffect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想淡入带有UIBlurEffect的UIVisualEffectsView进出:

I want to fade a UIVisualEffectsView with a UIBlurEffect in and out:

var blurEffectView = UIVisualEffectView()
blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))

我在一个内部使用普通动画由 UIButton 调用的函数淡入淡出,同样淡出,但 .alpha = 0 & hidden = true

I use a normal animation within a function called by a UIButton to fade it in, same for fading out but .alpha = 0 & hidden = true:

blurEffectView.hidden = false
UIView.animate(withDuration: 1, delay: 0, options: .curveEaseOut) {
    self.blurEffectView.alpha = 1
}

现在,两个方向的淡入都可以正常工作,但在淡出 out 时会出现错误:

Now, fading in both directions does work but it gives me an error when fading out:


< UIVisualEffectView 0x7fdf5bcb6e80> 被要求为其不透明度设置动画。这将导致效果显示为不透明度,直到不透明度返回到1.

<UIVisualEffectView 0x7fdf5bcb6e80> is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.

问题

如何成功淡入 UIVisualEffectView 而不会打破并且有一个渐弱的过渡?

How do I successfully fade the UIVisualEffectView in and out without breaking it and having a fading transition?

注意


  • 我试图把 UIVisualEffectView 进入 UIView 并淡化那一个,没有成功

  • I tried to put the UIVisualEffectView into a UIView and fade that one, no success

推荐答案

我认为这是iOS9中的新功能,但您现在可以设置 UIVisualEffectView 的效果在动画块内:

I think this is new in iOS9, but you can now set the effect of a UIVisualEffectView inside an animation block:

let overlay = UIVisualEffectView()
// Put it somewhere, give it a frame...
UIView.animate(withDuration: 0.5) {
    overlay.effect = UIBlurEffect(style: .light)
}

将其设置为 nil 以删除。

非常重要 - 在模拟器上进行测试时,请确保将模拟器的图形质量覆盖设置为高质量,以使其正常工作。

这篇关于如何淡入和淡出UIVisualEffectView和/或UIBlurEffect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆