2

コンテナコントローラーの子であるビューコントローラーがあり、デバイスの向きが変わったときにビューのサイズ変更を処理する方法を知りたいです。子コントローラーは、予期されたviewWillLayoutSubviewsイベントを受信して​​いません。

ビューの境界が変更されたときに「viewWillLayoutSubviews」が呼び出されるという印象を受けていますが、境界値はChildViewControllerのwillRotateToInterfaceOrientationイベントとdidRotateFromInterfaceOrientationイベントの間で同じままです。 何故ですか?

ローテーション中に表示されるビュー固有のイベントは次のとおりです。

[ParentViewController viewDidLoad]
[ParentViewController viewWillLayoutSubviews]
[ParentViewController layoutHomeForStartup]
[ParentViewController viewDidAppear:]
[ParentViewController showLoginView]

[ChildViewController viewDidLoad]
[ChildViewController didMoveToParentViewController:]

[ParentViewController viewWillLayoutSubviews]

[ChildViewController viewWillLayoutSubviews]
[ChildViewController viewDidAppear:]
[ChildViewController showLoginPanel]

[ParentViewController willRotateToInterfaceOrientation:duration:]
[ChildViewController willRotateToInterfaceOrientation:duration:]

[ParentViewController viewWillLayoutSubviews]
// QUESTION: Why doesn't the childViewController not receive viewWillLayoutSubviews?

[ParentViewController didRotateFromInterfaceOrientation:]
[ChildViewController didRotateFromInterfaceOrientation:]

子コントローラーを親に追加する方法は次のとおりです。

// ParentViewController:
- (void)viewDidLoad
{
    ChildViewController *childViewController = [ChildViewController alloc] initWithNibName...];

    [childController willMoveToParentViewController:self];
    [self addChildViewController:childController];
    [view addSubview:childController.view];
    [childController didMoveToParentViewController:self];
}

私はまだiOS5.0以降のデバイスをターゲットにしているので、以下も実装しました。

- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers 
{
    return YES;
}

shouldAutomaticallyForwardAppearanceMethodsまた、shouldAutomaticallyForwardRotationMethods実装され、YESを返します(iOS 6以降を使用している場合)。

コンテナコントローラーの子ビューコントローラー内で方向の変更を処理するための最良の方法がわかりません。

4

1 に答える 1

0

1.

automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers実際には2つの方法があります:

彼らは呼ばれshouldAutomaticallyForwardRotationMethodsshouldAutomaticallyForwardAppearanceMethods

IOS5 での 1 つのメソッドであったとしても、IOS6 にも新しいバリアントを実装する必要があります。

2.

あなたがコメントで言ったように、子供たちの境界は変わらないようです。これは理にかなっています。したがってsetNeedsLayout、View Controllerのビューを呼び出して、それらを自分でレイアウトします:)

于 2013-03-10T18:33:20.533 に答える