サイドバーを含み、コンテンツ領域のビューコントローラーを交換する非常に基本的なコンテナービューがあります(UISplitViewを考えてみてください。ただし、小さなアイコンのサイドバー/垂直UITabBarがあります)。
コンテナビューコントローラはautoLayoutを使用し、回転すると正しくサイズ変更されます。コンテンツviewController1は自動レイアウトを使用し、IBで作成されているため、xibファイルがあります。コンテンツviewController2はUITableViewControllerを継承し、xibを使用しません。
ビューコントローラー1をルートビューコントローラーとして割り当てて回転すると、サイズ変更が機能し、viewController1で取得するコールバックは次のようになります。
- willRotateToInterfaceOrientation
- updateViewConstraints
- viewWillLayoutSubviews
- didRotateFromInterfaceOrientation
ただし、コンテナビューコントローラをルートビューコントローラとして割り当て、viewController 1をロードして回転すると、サイズ変更が機能しません。そして、viewController1内で次のコールバックのみを取得します。
- willRotateToInterfaceOrientation
- didRotateFromInterfaceOrientation
ビューコントローラーコンテナ内で、ビューコントローラーを交換する方法は次のとおりです。
[self addChildViewController:toViewController];
[toViewController didMoveToParentViewController:self];
// Remove the old view controller
[fromViewController willMoveToParentViewController:nil];
[fromViewController.view removeFromSuperview];
[fromViewController removeFromParentViewController];
// Add the new view
[self.contentContainerView addSubview:toViewController.view];
これで、ローテーションが発生しようとしているというコールバックを取得しましたが、updateViewConstraintsもviewWillLayoutSubviewsも呼び出されていないようです。これは、サイズ変更が行われない理由を説明していますが、View Controllerをコンテナービューに配置すると、これらのメソッドが呼び出されないのはなぜですか?
また、両方のコンテナで明示的にYESを返そうとしました
shouldAutomaticallyForwardAppearanceMethods
と
shouldAutomaticallyForwardAppearanceMethods
これはすでにデフォルトになっているはずですが。
また、IBで作成されていないView Controller(View Controller 2)は、コンテナ内で回転すると正しくサイズ変更されます。ただし、これには明示的にNSLayoutConstraintsを使用していないため、回転時のサイズ変更にはデフォルトでSpringsとStrutsが使用されていると思われます。
回転時に自動レイアウトビューコントローラーのサイズを正しく変更するには、ビューコントローラーコンテナーで他のイベントを転送する必要がありますか?