我有一个带纵向方向的rootviewcontroller的导航控制器。然后我想将第二个viewcontroller推向具有横向方向的堆栈。可悲的是,我发现无法强迫应用程序重新检查supportedInterfaceOrientations
。所以横向视图控制器显示在protrait中,直到用户将他的设备旋转到横向。
我准备了一个测试项目:https://github.com/buechner/InterfaceOrientationTest
甚至可以自动更改导航控制器堆栈中的方向吗?
答案 0 :(得分:2)
您可以在ViewController
内展示LandscapeViewController
以强行制作landscape
在viewDidLoad
的{{1}}
LandscapeViewController
在self.performSelector(#selector(LandscapeViewController.launchLandscapeScreen), withObject: nil, afterDelay:1)
LandscapeViewController
答案 1 :(得分:0)
可以这样做,但你必须制作UIStoryboardSegue子类
创建UIStoryBoradSegue
的子类并覆盖perform()
override func perform() {
let sourceVC = self.sourceViewController
let destonationVC = self.destinationViewController
sourceVC.navigationController!.presentViewController(destonationVC, animated: true, completion: nil)
}
在您的NavigationControllerSubclass中更改shouldAutoRotate
和supportedInterfaceOrientations
public override func shouldAutorotate() -> Bool {
return (self.topViewController?.shouldAutorotate())!
}
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations())!
}
从viewControllers连接Segue时选择你的segue子类
4.在每个班级中添加shouldAutorotate
和supportedInterfaceOrientations
个方法
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait // or landscape in case you want orientation to be landscape
}