我有一个包含其他 ViewControllers 的 UIViewController。初始 ViewController 在 viewDidLoad 中设置:
FirstViewController *first = [FirstViewController alloc] init];
first.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
first.view.frame = m_content.frame;
[self addChildViewController:first];
[m_content.view addSubview:first.view];
[first didMoveToParentViewController:self];
m_activeViewController = first;
这个容器控制器已经实现了自动ForwardAppearanceAndRotationMethodsToChildViewControllers来返回YES。它还实现了对非活动视图控制器的手动正向旋转更改
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
for(UIViewController *vc in m_viewControllers)
{
if(vc != [m_activeViewController]
[vc willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
for(UIViewController *vc in m_viewControllers)
{
if(vc != [m_activeViewController]
[vc didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
}
当点击菜单按钮时,我会在 ViewControllers 之间进行转换。
- (void)onMenuItemTapped:(id)sender
{
UIViewController *vc = [m_viewControllers objectAtIndex:sender.tag];
vc.view.frame = m_content.frame;
[self addChildViewController:vc];
[self transitionFromViewController:m_activeViewController toViewController:vc duration:0 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) {
[vc didMoveToParentViewController:self];
[m_activeViewController removeFromParentViewController];
m_activeViewController = vc;
}];
}
这种过渡适用于我的“普通”视图控制器,并且它们在方向更改后正确显示,即使它们未处于活动状态。但是,其中一个称为 SecondCV 的子视图控制器将UIPageViewController作为子视图控制器。我将UIPageViewControllerDelegate和UIPageViewControllerDataSource设置为此 SecondCV 并在pageViewController:spineLocationForInterfaceOrientation 中:我为纵向返回 UIPageViewControllerSpineLocationMin,为横向返回 UIPageViewControllerSpineLocationMid。此 SecondVC 的旋转在其处于活动状态时可以正常工作 - 有两个页面在横向模式下,一个在纵向模式下正确显示。但是当这个 SecondVC 不活动时,旋转是不正确的。即使调用了 pageViewController:spineLocationForInterfaceOrientation:,Portrait 和 Landscape 模式下仍然有一个页面。我正在尝试解决此问题一段时间,但我没有看到任何其他选项。你有任何想法如何解决这个问题吗?
谢谢你。