0

我正在使用 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

我该如何解决这个问题?

4

0 回答 0