啓動屏幕當前默認爲設備當前的方向。 我試圖以編程方式設置它,但它仍然不起作用。Xcode - 強制啓動屏幕在橫向加載
override func viewDidLoad() {
super.viewDidLoad()
if UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait || UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown || UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown {
UIDevice.currentDevice().setValue(UIInterfaceOrientation.LandscapeLeft.rawValue, forKey: "orientation")
}
}
設備的取向是不會被'viewDidLoad中()'注意到,因爲在'viewDidLoad中()'運行的代碼視圖呈現之前。你編寫的代碼(或類似的東西)可以在'viewWillAppear()'中使用。我意識到這個問題很古老,但我認爲我的評論可能對提問人員以外的人有用。 – ClayJ