1、Appdelegate
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
ifself.allowRotation=="1"{
return UIInterfaceOrientationMask.landscape
}else{
return UIInterfaceOrientationMask.portrait
}
}
2、vc 需要横屏的页面
let appdelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.allowRotation="1"
返回的时候
let appdelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.allowRotation="0"
UIDevice.switchNewOrientation(interfaceOrientation: .portrait)
网友评论