UIInterfaceOrientation总是在AppDelegate iPad中返回Portrait?

我想在iPad应用程序中显示启动画面。 在此之前,我想获得当前的设备方向横向或纵向模式。 我用过,

UIInterfaceOrientation orientation= [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft) { splachview=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; splachview.image=[UIImage imageNamed:@"Default-Landscape.png"]; splachview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; splachview.contentMode = UIViewContentModeTop; [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO]; [self.window addSubview:splachview]; } else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { splachview=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)]; splachview.image=[UIImage imageNamed:@"Default-Portrait.png"]; splachview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; splachview.contentMode = UIViewContentModeTop; [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO]; [self.window addSubview:splachview]; } 

Appdelegate.m 。 UIInterface定向始终仅在纵向模式下检测。 我在横向模式下启动了应用程序,但控件始终只检测纵向模式。 如何在AppDelegate.m获取当前方向? 请帮我找到解决方案。 提前致谢。

你不应该在AppDelegate上这样做,而是在UIViewController 。 在UIViewController您可以使用类提供给您的相应方法 ( 配置视图旋转设置部分),正确地知道设备的位置。

阅读完代码后,看起来你想要的是在app启动时显示静态图像。 没有任何代码就有办法做到这一点。

http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/App-RelatedResources/App-RelatedResources.html#//apple_ref/doc/uid/TP40007072-CH6-SW12

如果要将任何动态内容显示为“splash”,则可能需要在UIViewController中处理它。

要获取当前设备方向,您可以读取属性:[UIDevice currentDevice] .orientation。 仅供参考。