我有一个包含其他视图控制器的UIViewController。在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;
该容器控制器已经实现了automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers方法并返回了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];
}
}
当菜单按钮被点击时,我会在视图控制器之间进行转换。
- (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:中返回了Portrait的UIPageViewControllerSpineLocationMin和Landscape的UIPageViewControllerSpineLocationMid。当这个SecondVC处于活动状态时,它的旋转是正确的 - 两个页面在横向模式下,一个页面在纵向模式下都被正确地显示。但当这个SecondVC不活动时,旋转是不正确的。即使调用了pageViewController:spineLocationForInterfaceOrientation:, 在纵向和横向模式下仍然只有一个页面。我试图解决这个问题有一段时间了,但我没有看到其他任何选择。你有没有什么想法如何解决这个问题?
谢谢。