iOS14 中缺少 AVPlayerViewController 播放控件

AVPlayerViewController playback controls missing in iOS14

我有一个嵌入 UIStackView 的 AVPlayerViewController。该代码在 iOS13 上运行良好,但在 iOS14 上我没有播放控件。当我点击视图时,播放控件不会出现,但当我做出捏合手势时,视频开始播放。当视频播放时,我突然得到了播放控件,我可以与它们互动。我的 TapableAVPlayerViewController 不是问题,因为我用标准 AVPlayerViewController 尝试过它,我得到了相同的行为。有时我什至会看到一个很大的播放按钮(就像在 iOS13 中一样),当视图完全加载时它会消失。

如何取回播放控件?任何帮助表示赞赏!谢谢!

private func setupVideo(for item: Item) {
    let avPlayer = AVPlayer()
    let avPlayerViewController = TapableAVPlayerViewController()
    avPlayerViewController.delegate = self
    avPlayerViewController.view.addInteraction(contextMenuInteraction)
    
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(DetailViewController.playerItemDidReachEnd(_:)),
                                           name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
                                           object: avPlayer.currentItem)

    avPlayerViewController.player = avPlayer
    avPlayerViewController.view.translatesAutoresizingMaskIntoConstraints = false
    avPlayerViewController.view.heightAnchor.constraint(equalToConstant: view.bounds.width * CGFloat(item.height) / CGFloat(item.width)).isActive = true
    addChild(avPlayerViewController)
    stackView.removeArrangedSubview(imageView)
    stackView.insertArrangedSubview(avPlayerViewController.view, at: 0)
    avPlayerViewController.didMove(toParent: self)
    let url = URL(string: viewModel.link)
    let playerItem = AVPlayerItem(url: url!)
    avPlayer.replaceCurrentItem(with: playerItem)
    self.avPlayer = avPlayer
    self.avPlayerViewController = avPlayerViewController
}

我找到了解决办法。看起来 UIContextMenuInteraction 破坏了播放控制。当我在整个 AVPlayerViewController 设置代码之后设置交互设置时,我恢复了播放控件。