我很想知道是否有某种方法可以确定iPhone / iPad上的屏幕方向。
目前,当发出此消息时,我发现自己设置了一个成员变量:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
self.orientation = interfaceOrientation;
return YES;
}
...感觉就像我应该能够查询状态而不是在变化时跟踪它。
答案 0 :(得分:11)
UIViewController具有interfaceOrientation属性。
不要对UIDevice中的方向感到困惑,因为UIDevice不是界面的方向,而是物理方向。
答案 1 :(得分:11)
如果您的状态栏位于顶部,请使用此选项。
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// portrait
} else {
// landscape
}
答案 2 :(得分:1)
你可以[[UIDevice currentDevice] orientation]
。