我在 IB 中创建了一个 UIVisualEffectView 和一个属性
@IBOutlet weak var visualEffectStack: UIVisualEffectView!
我可以使用
显示和隐藏视觉效果 ViewvisualEffectStack.isHidden = false
visualEffectStack.isHidden = true
或使用 alpha。
我想为 View 的外观设置动画,但它没有设置动画。
visualEffectStack.alpha = 0
visualEffectStack.isHidden = false
UIView.animate(withDuration: 0.5, delay: 0.5, options: [.curveEaseIn, .beginFromCurrentState], animations: {
self.visualEffectStack.alpha = 1
})
是我的代码有问题还是视觉效果 View 有问题?
swift 3.1 和 iOS 10
最佳答案
在做了更多研究后,我发现 UIVisualEffectView
应该始终保持 alpha = 1。因此动画 alpha
或 isHidden
永远不应该做完了。
Setting the Correct Alpha Value
When using the UIVisualEffectView class, avoid alpha values that are less than 1. Creating views that are partially transparent causes the system to combine the view and all the associated subviews during an offscreen render pass. UIVisualEffectView objects need to be combined as part of the content they are layered on top of in order to look correct. Setting the alpha to less than 1 on the visual effect view or any of its superviews causes many effects to look incorrect or not show up at all.
关于ios - UIView.animate 没有为我的 UIVisualEffectView 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43379675/