7

最近、コードを iPhone アプリから iPad に移植するときに問題が発生しました。ここで説明されている問題に関連している可能性がありますが、その質問の説明/解決策は不十分であることがわかりました. シナリオは次のとおりです。

  1. ビュー コントローラー 'A' (ルート ビュー コントローラー) は、モーダル ビュー コントローラー ('B' と呼びます) を "フォーム シート" モーダル プレゼンテーション スタイルで表示します。

  2. ビュー コントローラー B は、ビュー コントローラー 'C' を "フル スクリーン" モーダル プレゼンテーション スタイルで表示します。

  3. ビュー コントローラー C が一番上に表示されているビュー コントローラーである間に、iPad が回転します。

  4. C を閉じると、B が再表示されますが、向きが正しくありません。

私が知る限り、提示された複数のView Controllerの連鎖に問題はないはずです。実際、この動作はPresenting View Controllers from Other View Controllersのドキュメントで明示的にサポートされています。また、 iOS 5 リリース ノートの次のステートメントも読みました。

iOS 5 の回転コールバックは、全画面表示されるビュー コントローラーには適用されません。これが意味することは、コードが別のView Controllerの上にView Controllerを提示し、その後ユーザーがデバイスを別の方向に回転させた場合、却下時に、基礎となるコントローラー(つまり、提示するコントローラー)は回転コールバックを受信しないということです。ただし、表示中のコントローラーは、再表示時に viewWillLayoutSubviews 呼び出しを受け取り、このメソッドから interfaceOrientation プロパティを照会して、コントローラーを正しくレイアウトするために使用できることに注意してください。

私が知る限り、これは発生しません-ビューコントローラーBは-shouldAutoRotateToInterfaceOrientationへの呼び出しを受け取りますが、この呼び出しのinterfaceOrientationパラメーターの値は、値ではなく、ビューコントローラーCを提示したときのビューコントローラーBのインターフェイスの向きの値です却下時の C のインターフェイスの向き。iPad を使用しているため、これらすべてのビュー コントローラーは -shouldAutoRotateToInterfaceOrientation で YES を返します。したがって、B のビューの境界は変更されないため、-willLayoutSubviews は呼び出されません。

Bが閉じる前にBへのコールバックでView Controller Cの向きを保存し、次にその情報を使用して-shouldAutoRotateToInterfaceOrientationが呼び出され、Cの向きが閉じられたときにのみYESを返すようにしました。これにより、このチェックを行わずに表示される壊れた UI が修正されますが、ビュー コントローラー B はインターフェイスの向きをこの値に更新しないため、後続のモーダル プレゼンテーションはデバイスの間違った側からイン/アウトしてアニメーション化されます。

このようなView Controller構成を正常に取得できた人はいますか? それほど珍しいシナリオではないように見えるので、最初に期待したように機能していないことに少し驚いています。

前もって感謝します。

4

2 に答える 2

0

In my opinion multiple chained modal view controllers result in a confusing and annoying user experience if you don't use a navigation controller. I think View controller B should be in a navigation controller (you don't have to show the nab bar if you don't want).

Modal presentation is really supposed to be for single dead-ended entities (a single view controller or a navigation controller containing multiple children view controllers).

Out of interest, are you saying that this works fine on iPhone but not on iPad? Or did you not allow rotation on the iPhone version?

I've also found this thread which says that presenting your modal view controllers from the root view controller may help.

于 2012-07-02T11:06:17.877 に答える
0

私は、iPhone に表示される複数のモーダル ビュー コントローラーに取り組んできました。複数の向きを処理するための独自のコードに問題がない限り、レイアウトに問題はありません。ビューコントローラーが別のビューコントローラーの背後にある場合、自動回転メソッドは実際には呼び出されないため、viewWillAppear: のレイアウトも調整します。

viewWillAppear:、willRotateToInterfaceOrientation:duration:、および didRotateToInterfaceOrientation: では、必要に応じてレイアウトを正しい向きに調整します。次に例を示します。

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self switchToInterfaceOrientation:self.interfaceOrientation];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:interfaceOrientation duration:duration];
    [self switchToInterfaceOrientation:toInterfaceOrientation];
    // be careful, self.view.frame is still according to self.interfaceOrientation
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    // self.view.frame is updated
    // update something else here
}

- (void)switchToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // update your layout here
}

上記のコードが iPad のビュー コントローラーでどのように動作するかはわかりません。さまざまなモーダル プレゼンテーション スタイルのビュー コントローラーをサポートしているため、いくつかの驚きがあるかもしれません。

于 2013-05-16T04:41:35.470 に答える