他の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;
この Container Controller は、YES を返すように自動的に ForwardAppearanceAndRotationMethodsToChildViewControllers を実装しています。また、非アクティブな ViewController への前方回転の変更を手動で実装しています。
- (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];
}
}
メニュー ボタンがタップされると、ViewController 間の遷移を行います。
- (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;
}];
}
このトランジションは、「通常の」ViewController では正常に機能し、アクティブでない場合でも、方向の変更後に適切に表示されます。ただし、SecondCV と呼ばれるこれらの子ビュー コントローラーの 1 つには、子ビュー コントローラーとしてUIPageViewControllerがあります。UIPageViewControllerDelegateとUIPageViewControllerDataSourceをこの SecondCV と pageViewController:spineLocationForInterfaceOrientation に設定しています。ポートレートの場合は UIPageViewControllerSpineLocationMin を返し、ランドスケープの場合は UIPageViewControllerSpineLocationMid を返します。この SecondVC の回転は、アクティブなときに正しく機能します。横向きモードで 2 ページ、縦向きモードで 1 ページが正しく表示されます。しかし、この SecondVC がアクティブでない場合、ローテーションは正しくありません。pageViewController:spineLocationForInterfaceOrientation:が呼び出された場合でも、ポートレート モードとランドスケープ モードの両方で 1 つのページがまだ存在します。しばらくこれを修正しようとしていますが、他のオプションが表示されません。これを修正する方法はありますか?
ありがとうございました。