手机横竖屏问题

最近做了一个视频播放的功能,接入

https://github.com/changsanjiang/SJVideoPlayer/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B 快速开始

关键代码:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        
        if isLandscape == true {
            return .all
        }
        return .portrait
    }

这个方法每个VC都会走,决定是不是能横竖屏旋转。该方法实质上是制定window的方向,虽然一个app有多个VC,但是window都只有一个,所以这个指定了window的方向,那所有VC的方向就都是统一的。

而我希望的是,整个App竖屏,只有视频播放才可横屏,所以在这个方法中做了区分

在视频VC:

//MARK:该VC可横屏 其他均竖屏
    
    func backToPortrait() {//回到竖屏
        let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.isLandscape = false
    }
    
    func enterToLandscape() {//进入横屏
        let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.isLandscape = true
    }

参考:https://www.jianshu.com/p/f917df3e3b2e

此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
原文地址:https://www.cnblogs.com/liuw-flexi/p/13393686.html