[英]How to stop the device Orientation changing
如果在应用启动后无法立即设置方向,则可能需要停止每个视图控制器或其基本导航控制器之一的方向
斯威夫特3:
class YourBaseNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .portrait
}}
使用YourBaseNavigationController作为导航控制器。基本上,此导航控制器中的所有视图控制器都将仅支持纵向模式。
取消标记支票左横向和右横向
您需要通过代码禁用定向。
在您的RootViewController中添加以下代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);//set 'return NO'; for stop orientation
}
斯威夫特 :
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.