2

2 つのタブにナビゲーション ビューを含むタブ バー アプリケーションがあります。1 つのナビゲーション コントローラーの 1 つのビューで横向きのビューを許可したいのですが、タブ バーの制限のナビゲーション バーのため、アプリのすべてのビューで横向きのビューを許可して、チルト メッセージがアプリに渡されるようにする必要があります。したくない。

おそらく、横向きにすべきではないビューでは、デバイスが横向きになるたびに setOrientation:UIDeviceOrientationPortrait を呼び出すなど、ビューの変更を防ぐか、ビューが変更されていないという錯覚を与えるなど、次のいずれかの方法があると思いました。回転したビュー上のモーダル ポートレート ビュー

共有したいアイデアや経験を持っている人はいますか? ここで最善のアプローチは何ですか?(1つのビューに縦向きと横向きのビューを表示できるようにするためだけに、すべてのビューに横向きのビューを設計する必要はありません)

4

1 に答える 1

2

私は最近同じ問題に対処しなければなりませんでした。私の解決策は次のとおりです。

回転できるようにしたいビューのUIViewController内に、通知ハンドラーを追加しますUIDeviceOrientationDidChangeNotification

-(void)viewDidLoad {


[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didRotateFromInterfaceOrientation)
                                             name:@"UIDeviceOrientationDidChangeNotification" object:nil];

}

didRotateFromInterfaceOrientationもちろん、メソッドを実装する必要があります。

そのメソッド内で、現在の向きを取得できます

 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

次に行ったのは、向きに基づいて、表示したいビューを評価することでした

switch (orientation) {
    case UIDeviceOrientationLandscapeLeft:
        NSLog(@"UIDeviceOrientationLandscapeLeft");
        [self presentModalViewController:LandscapeView animated:YES];

        break;
    case UIDeviceOrientationLandscapeRight:
        NSLog(@"UIDeviceOrientationLandscapeRight");

        [self presentModalViewController:LandscapeView animated:YES];

        break;
    case UIDeviceOrientationPortraitUpsideDown:
        NSLog(@"UIDeviceOrientationPortraitUpsideDown");
        [LandScapeview dismissModalViewControllerAnimated:YES];

        break;
    case UIDeviceOrientationPortrait:
        NSLog(@"UIDeviceOrientationPortrait");
        [LandscapeView dismissModalViewControllerAnimated:YES];
        break;

    case UIDeviceOrientationFaceUp:
        NSLog(@"UIDeviceOrientationFaceUp");

        break;

    case UIDeviceOrientationFaceDown:
        NSLog(@"UIDeviceOrientationFaceDown");
        break;

    default:
        break;
    }
}

少しでもお役に立てれば幸いです。

于 2010-05-06T07:26:06.530 に答える