从 AVPlayerViewController.customoverlayViewController 移除 UIVisualEffect

Removing UIVisualEffect from AVPlayerViewController.customoverlayViewController

我正在实施 AVPlayerViewController.customOverlayViewController,我想知道是否有办法删除 UIVisualEffect 并在演示文稿上应用清晰的背景。我附上了 Hirechay 视图的屏幕截图。

根据视图层级,ChannelViewController是AVxCustomOverlayHostViewController的一部分,其AVxHostView类型的视图包含UIVisualEffectView。所以:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    // Remove UIVisualEffectView
    if let parent = parent {
        parent.view.subviews.filter({ [=10=] is UIVisualEffectView }).forEach({ [=10=].alpha = 0 })
    }
}

如果你想要也可以删除它。

@Reimond Hill 的回答很棒。谢谢你。 您可能需要删除底部间距并固定高度以构建完全相同的覆盖视图,以在故事板或 xib 文件中填充屏幕的整个宽度和高度。在这种情况下,我们必须修改约束。

这是我在控制台日志面板中看到的内容。

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600002dd1d10 AVxHostView:0x7fc3163678f0.height == 1140  (active)>
Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600002d800f0 UIView:0x7fc312c8ff10.bottom == AVxHostView:0x7fc3163678f0.bottom - 60  (active)>

解决这个问题的方法:

if let parent = parent {
    parent.view.subviews.filter({ [=11=] is UIVisualEffectView }).forEach({ [=11=].alpha = 0 })
        
    for constraint in parent.view.constraints {
        if let second = constraint.secondItem as? UIView,
            second == parent.view,
            constraint.secondAnchor == parent.view.bottomAnchor {
            constraint.constant = 0
        }
    }
            
    for constraint in parent.view.constraints {
        if let first = constraint.firstItem as? UIView,
            first == parent.view,
            constraint.firstAttribute == .height {
            constraint.constant = UIScreen.main.bounds.size.height
        }
    }
}