使用Swift将方向设置为纵向

Meg*_*gaX 4 ios swift

我有一个应用程序,其中一些屏幕应该是纵向模式,其中一些是横向模式.例如,主菜单是纵向,并且有一个相机按钮.相机应仅在横向上可用.我正在使用Storyboard和NavigationController.我应该在哪里以及如何做到这一点?

我已经尝试过包括

shouldAutorotate() -> Bool {return false or return true} 
Run Code Online (Sandbox Code Playgroud)

既没有奏效.我已经设定了

supportedInterfaceOrientation 
Run Code Online (Sandbox Code Playgroud)

对于我拥有的每个viewcontroller.什么都没有帮助.我需要一个功能,我可以调用强制屏幕进入横向/纵向模式.

gut*_*uhu 15

在ViewDidLoad中(或您想要的任何地方)使用此行代码.

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

3分钟前在Swift 1.2 Xcode 6.3中测试过

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

UIDevice.current.setValue(UIInterfaceOrientation.landscapeLe??ft.rawValue, forKey: "orientation")
Run Code Online (Sandbox Code Playgroud)

  • 苹果会拒绝app使用吗? (2认同)