问题描述
我想淡入带有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
而不会打破并且有一个渐弱的过渡?
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 aUIView
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!