微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift 播放器全屏显示

点击全屏按钮

    @objc func clickFullScreenButton() {
        isFullScreen.toggle()
        dispatchQueue.main.async {
            UIDevice.current.setValue(self.isFullScreen ? UIInterfaceOrientation.landscapeRight.rawValue : UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
        }
    }

 

    public var isFullScreen: Bool = false {//是否全屏
        didSet {
            dispatchQueue.main.async {
                if self.isFullScreen {
            //videoView 重新布局 self.videoView.snp.remakeConstraints { (remake) in remake.left.right.equalTo(0) remake.top.equalTo(0) remake.height.equalTo(ScreenWidth) } self.navigationController?.setNavigationBarHidden(true, animated: true) } else { self.videoView.snp.remakeConstraints { (remake) in remake.left.right.top.equalTo(0) remake.height.equalTo(180) } self.navigationController?.setNavigationBarHidden(false, animated: true) } self.view.bringSubviewToFront(self.videoView) } } }

 

给 ViewController 添加系统旋转通知

    NotificationCenter.default.addobserver(self, selector: #selector(orientationDidChange), name:UIDevice.orientationDidChangeNotification, object: nil)
sharedDelegate.rotate = true

@objc func orientationDidChange() { if playerItem == nil { return } let ttt = UIDevice.current.orientation if ttt == .landscapeLeft || ttt == .landscapeRight { isFullScreen = true } if ttt == .portrait { isFullScreen = false } }

 

 

AppDelegate 中 添加变量和方法

    var rotate = false
    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        if rotate {
            return .allButUpsideDown
        }
        return .portrait
    }

 

退出

    override func viewWilldisappear(_ animated: Bool) {
        sharedDelegate.rotate = false
        UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
    }

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐