app让个别界面横屏,其他的为竖屏,解决如下

时间:2023-03-09 00:21:01
app让个别界面横屏,其他的为竖屏,解决如下

app让个别界面横屏,其他的为竖屏,解决如下

app让个别界面横屏,其他的为竖屏,解决如下

APP设置里面,一定要设置可以旋转的方向

appdelegate里面重新系统方向代理

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {

return UIInterfaceOrientationMask.Portrait  // 设置全部为竖屏

}

在想要实现横屏的controller里面重写

是否支持自动横屏,

override func shouldAutorotate() -> Bool {

return false

}

支持的方向

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

return UIInterfaceOrientationMask.Landscape  // 代表横屏,左右横屏

}

物理显示屏幕,即将显示屏幕方向

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {

return UIInterfaceOrientation.LandscapeLeft

}

如果此controller含nav,应该在nav里面重写这个方法,controller不需要写