碰到一个功能就是使指定的页面横屏,然后找了一些方法其中之一是两句代码:如下(不推荐,有的swift环境支持有的不支持)
//MARK:将这个页面横屏的方法
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
let re = UIInterfaceOrientationMask.LandscapeLeft
return re
}
下面介绍一种稍微稳定点的方法
Declaration
SWIFT
optional func application(_ application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
OBJECTIVE-C
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
然后上官方文档:(很有用解释很全面)
This method returns the total set of interface orientations supported by the app. When determining whether