我正在使用Xcode 5.一旦应用程序进入AppDelegate.m,我想检测设备的方向,并根据设备是否处于纵向/横向模式,显示相应的视图控制器。
这是我的代码:
if (([[UIDevice currentDevice]orientation] == UIInterfaceOrientationPortrait) | ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationPortraitUpsideDown)) {
SplashScreenViewController *splashScreen = [[SplashScreenViewController alloc] initWithNibName:FILENAME_WITH_IDIOM(@"SplashScreenViewController") bundle:nil];
[self.mainWindowViewController presentViewController:splashScreen animated:NO completion:nil];
}
else if (([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft) | ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight)) {
SplashViewControllerLandscape *splashLandscape = [[SplashViewControllerLandscape alloc] initWithNibName:FILENAME_WITH_IDIOM(@"SplashViewControllerLandscape") bundle:nil];
[self.mainWindowViewController presentViewController:splashLandscape animated:NO completion:nil];
}
这只是让我看到一个空白屏幕。问题的原因是[[UIDevice currentDevice]orientation]
此方法返回UIDeviceOrientationUnknown
,除非打开设备方向通知。
如何解决此问题?