AVPlayerViewController 滑动 UISwipeGestureRecognizer.up 不工作 Xcode 12 tvOS 14

AVPlayerViewController Swipe UISwipeGestureRecognizer.up not working Xcode 12 tvOS 14

我们刚刚将 Xcode 更新到版本 12,除此之外,我们发现将 UISwipeGestureRecognizer.up 设置为 AVPlayerViewController 存在问题。我们使用该手势来显示自定义频道转换器视图。它在 Xcode 11.7 和 tvOS 13 上工作的主要问题。

此外,我调试了 AVPlayerViewController.view 的 gestureRecognisers,但没有 UISwipeGestureRecognizer。

这是我使用的代码

import UIKit
import AVKit

class ViewController: UIViewController {

    private var playerViewController: AVPlayerViewController? {
        didSet {
            guard let playerViewController = playerViewController else {
                return
            }
            
            playerViewController.view.isUserInteractionEnabled = true
            
            let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(testGestureResponse))
            //swipeGesture.direction = .up // Not working
            //swipeGesture.direction = .left
            //swipeGesture.direction = .down
            swipeGesture.direction = .right
            
            playerViewController.view.addGestureRecognizer(swipeGesture)
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        playerViewController = AVPlayerViewController()
        let playerViewController = self.playerViewController!
        
        playerViewController.willMove(toParent: self)
        view.addSubview(playerViewController.view)
        playerViewController.view.frame = view.frame
        addChild(playerViewController)
        playerViewController.didMove(toParent: self)
        
        playerViewController.player = AVPlayer(url: URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_adv_example_hevc/master.m3u8")!)
        playerViewController.player?.play()
    }

    
    @objc func testGestureResponse(gesture: UIGestureRecognizer) {
        print("Hello!!!")
    }

}

现在有不同的方法吗?

AVPlayerViewController.CustomOverlayViewController 是在 tvOS 13 中引入的,从 tvOS 14 显然是强制性的。如果你想在向上滑动时添加通道充电器(或任何其他视图),那么:

private var playerViewController: AVPlayerViewController? {
    didSet {
        guard let playerViewController = playerViewController else {
            return
        }
        playerViewController.customOverlayViewController = myChannelChangerVC
    }
}

资源