0

タブ バー コントローラーに 3 つのタブがあり、各タブにビュー コントローラーがあるアプリケーションが 1 つあります。ビュー コントローラー 1 と 2 はポートレート モードのみをサポートしていますが、タブ 3 のビュー コントローラーはすべての方向 (ポートレート、左横、右横、逆さまの縦) をサポートしています。タブ 3 では、デバイスが縦向きモードの場合は特定のビューを表示し、デバイスが横向きモードの場合は別のビューを表示する必要があります。

デバイスが縦向きモードで、ユーザーがタブ 3 をクリックすると、ビューが縦向きモードで正しく読み込まれ、デバイスを横向きモードに回転すると、横向きビューが正しく読み込まれます。

しかし、タブ 1 自体でデバイスを横向きモードにしてからタブ 3 をクリックすると、問題が発生し、横向きモードで表示される画面が表示されますが、縦向きビューとして表示されます。

NSLogging によるデリゲート メソッドでこの理由を調べようとしたところ、

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

interfaceOrientation の値は 1 であり、これは UIInterfaceOrientationPortrait であり、コントロールはポートレート モード用に記述された if 条件に入ります。

if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){

同じデリゲートメソッドで UIDevice の向きの値を出力しようとしたとき

UIDeviceOrientation interfaceOrientation = [UIDevice currentDevice].orientation;
NSLog(@" device orientation %u", interfaceOrientation);

コンソールに表示される値は 4 で、これは UIDeviceOrientationLandscapeRight です。

インターフェイスの向きは UIInterfaceOrientationPortrait ですが、デバイスの向きは UIDeviceOrientationLandscapeRight です。

もう1つ、デバイスを縦向きモードに回転させてから横向きモードに移動すると、正しい横向きビューが表示され、アプリが正しく動作し始めます。

したがって、問題は、タブ 3 をランドスケープ モードでロードすると正しくロードされないことですが、ポートレート モードに入り、そこから正常に動作する場合はランドスケープに回転します。

誰かがなぜこのような振る舞いをするのか、有益な提案をすることができれば、それは本当に有益です.

ありがとう

4

2 に答える 2

1

viewWillAppear メソッドでこれらの行を Tab1 & Tab2 に追加します。

#import <objc/message.h>

- (void)viewWillAppear:(BOOL)animated {
    if(UIDeviceOrientationIsLandscape(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
        }
    }
}
于 2013-09-20T09:22:46.690 に答える