手机横竖屏问题

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

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

posted @ 2020-07-28 20:34  liuw_flexi  阅读(184)  评论(0编辑  收藏  举报