zoukankan      html  css  js  c++  java
  • 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")
        }
    
  • 相关阅读:
    native2ascii转码工具的使用
    文件查找工具Everything小工具的使用
    sql中decode()重要函数使用
    java中随机生成汉字
    java中Random(long seed)方法与rRandom()方法的使用产生随机数
    WEB项目web.xml文件中classpath: 跟classpath*:使用的区别
    170809、 把list集合中的数据按照一定数量分组
    170808、生成为CVS文件
    170807、intellij idea maven集成lombok实例
    170804、使用Joda-Time优雅的处理日期时间
  • 原文地址:https://www.cnblogs.com/lion-witcher/p/13902367.html
Copyright © 2011-2022 走看看