【发布时间】:2016-05-23 17:35:29
【问题描述】:
我正在尝试以纵向模式锁定我的应用的一个视图。我有一个顶部导航控制器视图和多个嵌套场景。
我找到了很多关于锁定方向问题的答案并尝试了下面的代码,但它只能部分工作。让场景 A 和 B,其中 A 有一个segue 到 B,而 B 被锁定在纵向。如果我去 B 场景,将设备转到横向位置并返回 A,方向是从之前的 B(纵向)继承的。
如何让 A 场景识别实际的设备方向?
导航控制器
internal override func shouldAutorotate() -> Bool {
return visibleViewController!.shouldAutorotate()
}
“B”视图控制器
override func shouldAutorotate() -> Bool {
if UIDevice.currentDevice().orientation == .Portrait {
return true
}
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
override func viewDidLoad() {
super.viewDidLoad()
let orientation = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(orientation, forKey: "orientation")
}
【问题讨论】:
-
查看我的答案,如果对您有用,请给我反馈
标签: ios swift uiinterfaceorientation uideviceorientation