18

この問題は断続的に発生しているように見えますが、正確な理由はわかりません。デバイス(iPad)でアプリケーションを実行すると、現在のデバイスの向きに応じて、スクロールビューといくつかの画像ビューをロードするコードがあります。デバイスはロード前は横向きですが、ビューは縦向きであるかのようにロードされています。

方向は、を呼び出すことによって見つけられ[[UIApplication sharedApplication] statusBarOrientation]ます。

ビューは、デバイスが回転したときに位置を調整するように設定されています。実際、ポートレートに回転してからランドスケープに戻ると、ビューは正しいランドスケープ位置に戻ります。すべてのアプリケーションが縦向きで始まり、必要に応じてすぐに横向きに変わるのは事実ですか?init(ロードされる最初のView Controllerの間に)方向を確認するのが早すぎますか?

4

5 に答える 5

35

OK修正しました。

UINavigationControllerを使用して、popToViewController:animated:ランドスケープビューからポートレートビューに移動すると、宛先ビューは正しく表示されますが、ステータスバーとUIKeyboardはランドスケープ構成を維持し、実際の混乱を引き起こします。

回避 策statusBarOrientationとリファレンスに関する何千もの推奨事項を読んだ後... https: //developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-6_0/index.html

「setStatusBarOrientation:animated:メソッドは完全に非推奨ではありません。最上位のフルスクリーンビューコントローラーのsupportedInterfaceOrientationsメソッドが0を返した場合にのみ機能するようになりました。これにより、呼び出し元はステータスバーの向きが一貫していることを確認する責任があります。」(ここのVytisに感謝します)

statusBarOrientationは、supportedInterfaceOrientationsが0を返す場合にのみ機能するため、推測が可能です。

statusBarOrientationが期待どおりでない場合は、1回のゼロリターンでそれが行われます(常に0を返す場合、ビューは回転しないため、次のようになります。

// if deviceOrientation is A (so I expect statusbarOrientation A
// but statusbarOrientation is B
// return 0
// otherwise 
// return user interface orientation for A

- (NSUInteger)supportedInterfaceOrientations {
    UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    UIInterfaceOrientation statusBarOrientation =[UIApplication sharedApplication].statusBarOrientation;
    if(deviceOrientation == UIDeviceOrientationPortrait || deviceOrientation == UIDeviceOrientationPortraitUpsideDown){
        if(statusBarOrientation != UIInterfaceOrientationPortrait ||statusBarOrientation != UIInterfaceOrientationPortraitUpsideDown){
             return 0;
        }
    }
    // otherwise
    return UIInterfaceOrientationMaskPortrait;
}

さて、viewDidAppearで(私を信じてください、私はキーボード通知が受信されたときでさえこの呼び出しを使用します:

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

これで48時間以上の労働時間。皆さんのおかげで、これがしばらくお役に立てば幸いです。

于 2013-01-25T20:47:37.720 に答える
7

UIWindowまたはステータスバーをサブクラス化する場合は、これがipadデバイスのネイティブの向きであるために表示されます。UIWindowは、方向と座標を私たちが慣れているものに変換します。makeAndKeyVisibleを作成すると、ViewControllerでのデバイスとインターフェイスの向きが期待どおりになるはずです。たまたまMTStatusBarOverlayを使用していませんか?私は同じことを経験しました、そしてそれは主張の順序に行き着きました。

于 2011-05-03T04:07:39.087 に答える
4

他の誰かがこれに遭遇した場合に備えて、iOS5、実際にはiPhoneで同様の問題を抱えているアプリがたくさんあります。

iOS 5のバグか、一般的な動作への干渉である可能性があります...

カスタムルートビューコントローラークラス(UITabBarControllerサブクラス、それが重要かどうかはわかりません)を使用し、そのクラスで「shouldAutorotateToInterfaceOrientation」をオーバーライドして、最初の画面設定が完了した後にのみ回転を開始しました(そうでない場合は混乱します)。

私が今していることは、このクラスを再利用して、回転を許可する前にstatusBarOrientationを手動でportraitに設定し、その後UIが回転するものに設定することです。

[[UIApplication sharedApplication] setStatusBarOrientation:toInterfaceOrientation animated:YES];

原因が無関係であっても、これでこの問題も修正できると思います。

于 2011-08-16T00:12:48.517 に答える
1

起動時にこの問題が発生する場合は、UIDeviceを使用してデバイスの向きを取得する必要があります。これは、statusBarOrientationがapplication:didFinishLaunchingWithOptions:の後まで常に縦向きになるためです。唯一の注意点は、事前にデバイスの向きの通知を有効にするか、UIDeviceに向きを尋ねる必要があることです。

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
于 2013-03-20T20:04:56.423 に答える
0

info.plistにこれらすべてがあることを確認しましたか?

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
于 2011-05-03T01:59:56.103 に答える