1

現在表示されているViewControllerのUIInterfaceOrientationを確認しようとしましたが、何らかの理由で常に横向きになります。

 UIInterfaceOrientation currentOrientation = (UIInterfaceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
            if (currentOrientation == UIInterfaceOrientationPortrait){
                self.scrollView_.colMargin = 50;
            } else {
                self.scrollView_.colMargin = 130;
            }

なぜですか?

4

3 に答える 3

1

向きは次のように確認できます。

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
    if( orientation == UIDeviceOrientationPortrait ) ...
于 2012-07-05T17:44:18.627 に答える
1

iOS UIDevice クラス リファレンスから:

オリエンテーション

デバイスの物理的な向きを返します。(読み取り専用)

討論

このプロパティの値は、beginGeneratingDeviceOrientationNotifications を呼び出して方向通知が有効になっていない限り、常に 0 を返します。

したがって、次のようなことを行う必要があります。

- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

そして、忘れないでください

    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

あなたが見たときDidUnload

于 2012-09-14T16:35:08.720 に答える
0

キャスティングは魔法ではありません。ステータスバーの向きは、インターフェイスの向きとは異なる値を使用します。代わりに、現在のViewControllerself.interfaceOrientationプロパティを使用してください。

于 2012-07-05T17:39:01.940 に答える