ios - UIView.animate 没有为我的 UIVisualEffectView 设置动画

标签 ios swift animation uiview uiviewanimation

我在 IB 中创建了一个 UIVisualEffectView 和一个属性

@IBOutlet weak var visualEffectStack: UIVisualEffectView!

我可以使用

显示和隐藏视觉效果 View
visualEffectStack.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。因此动画 alphaisHidden 永远不应该做完了。

来自 Apple's documentation :

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/

相关文章:

iphone - iOS 键盘记录器实现

ios - AVURLAsset trackWithMediaType 在模拟器中不返回 AVMediaTypeAudio 的 audioTracks

ios - 用户滚动时如何停止视频

c - swift (Linux) : Extract CMS/PKCS#7 Certs and Validate Container Signature?

javascript - 如何围绕特定点来回旋转对象?

javascript - 如何使用 JavaScript 测量动画发生的时间

iphone - iOS 从经过身份验证的 URL 流式传输音频

swift - 在 Xcode 8.2.1 中构建和运行的问题

ios - 在 Swift 中导入扩展文件

animation - 当动画已使用 Unity2D Sprite 中的 Animator 添加到游戏对象时,无法翻译游戏对象