2015-05-03 43 views
4

我有一個應用程序,其中一些屏幕應處於肖像模式,其中一些應處於橫向模式。例如,主菜單是肖像,並有一個照相機按鈕。相機只能在風景中使用。我正在使用Storyboard和NavigationController。我應該怎樣做才能做到這一點?使用Swift將方向設置爲肖像

我已經嘗試過包括

shouldAutorotate() -> Bool {return false or return true} 

既不工作。我已經爲每個viewcontroller設置了

supportedInterfaceOrientation 

。沒什麼幫助。我需要一個可調用的功能來強制屏幕進入橫向/縱向模式。

+0

這裏已經回答[答案](http://stackoverflow.com/questions/26357162/how-to-force-view-controller-orientation-in-ios-8) – MacKentoch

+0

這兩種解決方案都沒有e爲我工作。 :( – MegaX

回答

15

在你的ViewDidLoad(或任何你想要的地方)使用這行代碼。

斯威夫特1 UIDevice.currentDevice().setValue(UIInterfaceOrientation.LandscapeLeft.rawValue, forKey: "orientation")

在雨燕1.2測試3分鐘前的Xcode 6.3

斯威夫特3(感謝Fa.Shapouri)

UIDevice.current.setValue(UIInterfaceOrientation.landscapeLe‌​ft.rawValue, forKey: "orientation") 
+1

將蘋果拒絕使用它的應用程序? – Arefly

+0

** Swift 3 **:UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue,forKey:「orientation」) –

相關問題