3

我很想知道是否有某种方法可以确定 iPhone/iPad 上屏幕的方向。

目前,我发现自己在调用此消息时设置了一个成员变量:

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

...感觉就像我应该能够查询状态而不是在它发生变化时跟踪它。

4

3 回答 3

11

UIViewController 具有 interfaceOrientation 属性。

不要对 UIDevice 中的方向感到困惑,这不是界面的方向,而是物理方向。

于 2010-06-03T23:50:28.693 回答
11

如果顶部有状态栏,请使用此选项。

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

你可以做到[[UIDevice currentDevice] orientation]

于 2010-06-03T23:44:35.867 回答