ZFPlayer iOS16 系统横屏全屏问题处理

iOS16 以后 通过原始横屏的方法已经不好使了,需要在此基础上添加 setNeedsUpdateOfSupportedInterfaceOrientations 方法的调用,具体API 描述如下:

ZFPlayer iOS16 系统横屏全屏问题处理_第1张图片回到主题,在使用ZFPlayer 视频库全屏播放时iOS16系统下的处理参考如下:

//进入全屏播放事件
self.player.orientationWillChange = {[weak self] (player,isFullScreen) in
            guard let self = self else { return }
            
            if isFullScreen {
                var _title = self.model?.title ?? ""
                if self.model?.authorize == 0 {
                    _title += "(试看\(Int(Setting.shareInstance.K_APP_TRY_WATCH_INTERVAL/60))分钟)".replacingOccurrences(of: "\r", with: "")
                }
                
                if self.isVertical {
                    self.controlView.portraitControlView.showTitle(_title, fullScreenMode: .portrait)
                }
                else{
                    self.isAutorotate = true
                    self.faceOrientation = .landscapeRight
                   
                    if #available(iOS 16.0, *) {
                        //横屏
                        self.setNeedsUpdateOfSupportedInterfaceOrientations()

                        self.player.addPlayerView(toContainerView: UIApplication.shared.windows.first!)
                        
                    } else {
                        // Fallback on earlier versions
                        self.player.containerView = UIApplication.shared.windows.first!
                    }
                    self.controlView.landScapeControlView.showTitle(_title, fullScreenMode: .landscape)
                }
            }
}


//MARK: - 设备方向处理
extension StudyCourseDetailsViewController {
    
    override var shouldAutorotate: Bool {
        get {
            return self.isAutorotate
        }
    }
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        get {
            return self.faceOrientation
        }
    }
    
}

退出全屏的方法,无需调整,具体参考如下:

//退出全屏被点击(全屏返回按钮被点击)
self.playerControlView.backBtnClickCallback = {[weak self] in
            guard let self = self else { return }
            
            if self.isVertical == false {
                self.isAutorotate = false
                self.faceOrientation = .portrait
                
                self.player.rotate(to: .portrait, animated: true) {
                    print("已返回小屏")
                }
                
                self.player.containerView = self.videoPlayerView
            }
            
      self.player.enterFullScreen(false, animated: true)
}

更多关于iOS16 兼容性处理,参考:XCode14 & iOS16 适配问题汇总 

你可能感兴趣的:(IOS移动开发,iOS16,ZFPlayer全屏,横屏)