ra9*_*a9r 3 iphone screen-orientation ipad
我很想知道是否有办法确定iPhone/iPad上的屏幕方向.
目前我发现自己在调用此消息时设置了一个成员变量:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
self.orientation = interfaceOrientation;
return YES;
}
Run Code Online (Sandbox Code Playgroud)
...感觉像我应该能够查询状态,而不是在它发生变化时跟踪它.
Eik*_*iko 11
UIViewController具有interfaceOrientation属性.
不要对UIDevice中的方向感到困惑,因为UIDevice不是界面的方向,而是物理方向.
Sla*_*vik 11
如果您的状态栏位于顶部,请使用此选项.
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// portrait
} else {
// landscape
}
Run Code Online (Sandbox Code Playgroud)