【发布时间】:2012-04-13 08:16:29
【问题描述】:
我有一个包含其他 ViewController 的 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: 被调用,纵向和横向模式仍然有一个页面。我正在尝试解决此问题一段时间,但我没有看到任何其他选项。你有任何想法如何解决这个问题吗?
谢谢。
【问题讨论】:
标签: containers uipageviewcontroller screen-rotation