【发布时间】:2016-02-22 20:32:32
【问题描述】:
我从 UIPageViewContoller 类继承了 3 个视图控制器。其中两个应该只有纵向方向和一个 - 所有方向。我添加了这样一段代码:
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return self.currentStackVC.supportedInterfaceOrientations()
}
override func shouldAutorotate() -> Bool {
return self.currentStackVC.shouldAutorotate()
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return self.currentStackVC.preferredInterfaceOrientationForPresentation()
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
}
currentStackVC 是当前可见的视图控制器。 我的视图控制器中也有这样的代码,实现方式略有不同:
前两个视图控制器(下一个 - VC):
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
override func shouldAutorotate() -> Bool {
return false
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.Portrait
}
最后:
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.All
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.Portrait
}
当我位于第三个视图控制器上时 - 我旋转了我的设备并应用了新的方向。但不幸的是,它也适用于其他 VC。系统不会在第一个和第二个 VC 中询问 shouldAutorotate()。 (我认为因为每次只问当前的第三个 VC)。我去第二个VC(使用滑动),它也是横向的。所以,我的问题是 - 如何在 Page VC 中为不同的屏幕处理不同的方向?
提前致谢
【问题讨论】:
-
你解决了吗?
-
不,我没有。
标签: ios swift2 uipageviewcontroller uiinterfaceorientation