以编程方式退出AVPlayerViewController全屏?

时间:2018-06-11 09:20:41

标签: ios swift avplayerviewcontroller

我尝试自定义AVPlayerViewController显示全屏,我搜索链接: How to make a AVPlayerViewController go to fullscreen programmatically?。它在我使用私有方法时有效,但我找不到方法退出全屏。

2 个答案:

答案 0 :(得分:1)

我找到了适合我的解决方案

extension AVPlayerViewController {

func goFullScreen() {
    let selectorName: String = {
        if #available(iOS 11.3, *) {
            return "_transitionToFullScreenAnimated:interactive:completionHandler:"
        } else if #available(iOS 11, *) {
            return "_transitionToFullScreenAnimated:completionHandler:"
        } else {
            return "_transitionToFullScreenViewControllerAnimated:completionHandler:"
        }
    }()
    let selectorToForceFullScreenMode = NSSelectorFromString(selectorName)

    if self.responds(to: selectorToForceFullScreenMode) {
        self.perform(selectorToForceFullScreenMode, with: true, with: nil)
    }
}

func quitFullScreen() {
    let selectorName: String = {
        if #available(iOS 11, *) {
            return "_transitionFromFullScreenAnimated:completionHandler:"
        } else {
            return "_transitionFromFullScreenViewControllerAnimated:completionHandler:"
        }
    }()
    let selectorToForceQuitFullScreenMode = NSSelectorFromString(selectorName)

    if self.responds(to: selectorToForceQuitFullScreenMode) {
        self.perform(selectorToForceQuitFullScreenMode, with: true, with: nil)
    }
}
}

希望有帮助。

答案 1 :(得分:0)

我找到了一种解决方案,您可以退出并全屏显示。

如果有人寻找答案,希望对您有帮助...

import AVKit

extension AVPlayerViewController {

    func goFullScreen() {
        let selectorName = "enterFullScreenAnimated:completionHandler:"
        let selectorToForceFullScreenMode = NSSelectorFromString(selectorName)

        if self.responds(to: selectorToForceFullScreenMode) {
            self.perform(selectorToForceFullScreenMode, with: true, with: nil)
        }
    }

    func quitFullScreen() {
        let selectorName  "exitFullScreenAnimated:completionHandler:"
        let selectorToForceQuitFullScreenMode = NSSelectorFromString(selectorName)

        if self.responds(to: selectorToForceQuitFullScreenMode) {
            self.perform(selectorToForceQuitFullScreenMode, with: true, with: nil)
        }
    } 
}

让我知道是否适合您。