Exit AVPlayerViewController fullscreen programmatically?

偶尔善良 提交于 2021-02-10 06:37:15

问题


I am try customize AVPlayerViewController show fullscreen and I search link: How to make a AVPlayerViewController go to fullscreen programmatically?. It work when I use private method, but I can't find method exit full screen.


回答1:


I have found a solution to this problem that works for me

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)
    }
}
}

Hope it helps.




回答2:


I found a solution that you can go and exit fullscreen.

If someone look for an answer, I hope it helps...

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)
        }
    } 
}

Let me know if work for you.



来源:https://stackoverflow.com/questions/50794310/exit-avplayerviewcontroller-fullscreen-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!