[英]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.