3

iPhone/iPad で画面の向きを判断する方法があるかどうか知りたいと思っていました。

現在、このメッセージが呼び出されたときにメンバー変数を設定していることに気づきました。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   self.orientation = interfaceOrientation;
   return YES;
}

...これは、状態が変化したときに追跡するのではなく、状態としてクエリできるようにする必要があるように感じます。

4

3 に答える 3

11

上部にステータス バーがある場合は、これを使用します。

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
    // portrait             
} else {
    // landscape
}
于 2011-02-05T04:48:58.473 に答える
11

UIViewController には interfaceOrientation プロパティがあります。

インターフェイスの向きではなく、物理的な向きである UIDevice の向きに惑わされないでください。

于 2010-06-03T23:50:28.693 に答える
1

できます[[UIDevice currentDevice] orientation]

于 2010-06-03T23:44:35.867 に答える