只允许一个View Controller的所有方向 [英] Allow all orientations for only one view controller
问题描述
I know this question was already asked in here, here and here. I tried all possible ways but wasn't successful.
我正在尝试在Swift(iOS 8)中开发一个应用程序,在该应用程序中,只有一个视图控制器可以在所有方向上被查看,而其他视图则只能以纵向显示.
I'm trying to develop an application in Swift (iOS 8), in which only one view controller can be viewed in all orientations others in only portrait.
为此,我仅在目标"->常规"->设备方向"中启用了"Portrait
"模式(因为我希望应用程序只能在除一个视图控制器之外的纵向模式下运行).
For this, I have enabled only Portrait
mode in Target->General->Device Orientation (because I want the application to operate only in portrait mode except one view controller).
我已将以下代码添加到要在所有方向上操作的视图控制器:
I have added below code to the view controller that I want to operate in all orientations:
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.All.rawValue)
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.LandscapeLeft;
}
override func shouldAutorotate() -> Bool {
return true;
}
但是无法在横向模式下旋转它.
But couldn't rotate it in landscape mode.
推荐答案
执行以下操作:
- 在常规信息"屏幕中启用所需的方向 在每个
-
中,使用true或false覆盖自动旋转功能.
(true
表示应该旋转的一个,false
表示其他的旋转):
ViewController
中的- enable the desired orientations in the General Info Screen
in each
ViewController
, override the autorotation function with either true or false
(true
for the one that should rotate,false
for the others):
override var shouldAutorotate: Bool {
return true
}
希望有帮助:)
这篇关于只允许一个View Controller的所有方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!