ios - UIInterfaceOrientation 总是在 AppDelegate iPad 中返回 Portrait?

标签 ios ipad splash-screen uiinterfaceorientation

我想在 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 中,您可以通过 using the appropriate methods 正确知道设备的位置。 (配置 View 旋转设置部分)类(class)为您提供的内容。

关于ios - UIInterfaceOrientation 总是在 AppDelegate iPad 中返回 Portrait?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8816252/

相关文章:

ios - 在 SWIFT 中的不同 View 之间切换

ios - 我可以在包中嵌入自定义字体并从 ios 框架访问它吗?

ios - 从邮件中打开自定义文件后会调用哪种方法

android - MainActivity 在 SplashScreen 结束之前开始

jquery - 使用纯 CSS 和关闭按钮的启动页面

ios - iBeacons 在 iOS 10.0.2 中损坏?

ios - 如何以编程方式显示/推送导航 Controller

javascript - jQuery Flexslider 无法在 iPhone 和 iPad 上工作

iphone - 非法尝试在不同上下文中的对象之间建立关系

Android 启动画面 WepApp Sencha