在 Controller 中运行 viewDidLoad 方法之前,我需要检测设备方向。我尝试了针对其他问题的所有解决方案,但我无法解决。
在 xCode 5 和 iOS 7 中使用 SotryBoard 的最佳方式是什么?
提前致谢!
编辑:实际上我正在使用
- (void)viewDidLoad {
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
switch ([[UIDevice currentDevice] orientation]) {
case (UIDeviceOrientationPortrait):
// landscape layout
break;
default:
// portrait layout
break;
}
但它不起作用...
已解决:使用
- (void)viewDidLoad {
[super viewDidLoad];
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) {
// Portrait
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
// Landscape
}
}
最佳答案
[[UIDevice currentDevice] orientation]
是你需要的吗?
关于ios - 如何在 viewDidLoad 之前检测设备方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19707136/