我有以下代码:
-(void)viewWillAppear:(BOOL)animated {
UIDeviceOrientation orientation = [[UIDevice currentDevice] UIInterface];
if(orientation==UIDeviceOrientationLandscapeLeft || orientation==UIDeviceOrientationLandscapeRight) {
NSLog(@"Device Landscape");
} else {
NSLog(@"Device Portrait");
}
}
Run Code Online (Sandbox Code Playgroud)
这适用于模拟器和设备,但只有当iPad在表面上不平坦时,例如,如果我将iPad放在桌面上并加载视图,它会说出它的肖像,所以我无法检测到方向视图出现.
在调用viewWillAppear时检测界面方向的最佳方法的任何想法?
谢谢
[[UIApplication sharedApplication] statusBarOrientation] 如果您在代码中无法访问的位置,也可以使用 [self interfaceOrientation]
| 归档时间: |
|
| 查看次数: |
2731 次 |
| 最近记录: |