33

iOS6 を搭載した iPad では、「フォーム シート」プレゼンテーション スタイルを使用するように指示されていても、モーダル ビュー コントローラーが全画面表示になるというこのバグがあります。ただし、これは、親モーダルとその子モーダルの 2 つのモーダルがある場合にのみ発生します。

したがって、これが最初のモーダルの作成方法と表示方法です。

UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is my application's root controller

これは、子モーダルを作成して表示する方法です。

UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is the navigationController from above

したがって、横向きから縦向きに回転すると、親モーダルはフルスクリーンに拡大され、横向きに戻ってもそのままです。

親モーダルがすべて単独である場合 (子モーダルがない場合)、期待どおりに機能します。つまり、フォーム シート スタイルのままです。

これは iOS6 (デバイスとシミュレーター) でのみ発生し、iOS 5 (シミュレーターであり、テスターに​​よって動作することが報告されています) では発生しないことに注意してください。

これまでのところ、成功せずに次のことを試しました。

  • wantsFullScreenLayoutに設定NO
  • オーバーライドしwantsFullScreenLayoutて常に強制的に返すNO
  • ナビゲーションコントローラー内の特定のコントローラーを指定することも指定しますUIModalPresentationFormSheet
  • 実装するpreferredInterfaceOrientationForPresentation
  • iOS 6.0.1 へのアップグレード

ありがとう!


更新: したがって、複数のネストされたモーダルで動作するように、Apple Developer Forums ( https://devforums.apple.com/message/748486#748486 ) からの応答を調整しました。

- (BOOL) needNestedModalHack {
    return [UIDevice currentDevice].systemVersion.floatValue >= 6;
}

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                          duration:(NSTimeInterval)duration {

    // We are the top modal, make to sure that parent modals use our size
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
        for (UIViewController* parent = self.presentingViewController;
             parent.presentingViewController;
             parent = parent.presentingViewController) {
            parent.view.superview.frame = parent.presentedViewController.view.superview.frame;
        }
    }

    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                 duration:(NSTimeInterval)duration {
    // We are the top modal, make to sure that parent modals are hidden during transition
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
        for (UIViewController* parent = self.presentingViewController;
             parent.presentingViewController;
             parent = parent.presentingViewController) {
            parent.view.superview.hidden = YES;
        }
    }

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    // We are the top modal, make to sure that parent modals are shown after animation
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
        for (UIViewController* parent = self.presentingViewController;
             parent.presentingViewController;
             parent = parent.presentingViewController) {
            parent.view.superview.hidden = NO;
        }
    }

    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
4

3 に答える 3

7

これがバグと見なされるべきかどうかは不明であり、iOS 7 がもたらすものに興味がありますが、この問題に対する現在の回避策は、modalPresentationStyle を child-viewController の UIModalPresentationCurrentContext に設定することです。

Set modalPresentationStyle = UIModalPresentationCurrentContext

これにより、子は引き続き FormSheet として表示されますが、親が回転時にフルスクリーンにサイズ変更されるのを防ぎます。

ダーク

于 2013-05-28T07:18:14.817 に答える
0

ここに 2 つの問題があります。

1) iOS 6 ではこのメソッドpresentModalViewController:animated:は廃止されpresentViewController:animated:completion: ました。

2) iOS 6 では、コンテナー コントローラー ( などUINavigationController) が自動回転メッセージを子に再送信しないように見えました。をサブクラス化UINavigationControllerし、対応する自動回転メソッドを再定義して、すべての子に送信してみてください。これは役立つかもしれません。

于 2013-05-10T10:58:52.280 に答える