我从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是当前可见的视图控制器。 此外,我在视图控制器中有这样的代码,有一些不同的实现:
前两个viewcontrollers(下一个 - 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中询问shouldAutorotate()。 (我认为因为每次只询问当前的第3个VC)。我转到第二个VC(使用滑动),它也是横向的。所以,我的问题是 - 如何在不同的屏幕上处理页面VC的不同方向?
提前致谢
答案 0 :(得分:1)
你应该使用UIPageViewController的委托方法
- (UIInterfaceOrientationMask)pageViewControllerSupportedInterfaceOrientations:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
例如,将此代码放入UIPageViewController的委托
- (UIInterfaceOrientationMask)pageViewControllerSupportedInterfaceOrientations:(UIPageViewController *)pageViewController {
return [[pageViewController.viewControllers lastObject] supportedInterfaceOrientations];
}
并覆盖子VC中的方法。
VC1
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
VC2
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}