问题
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