【问题标题】:UIInterfaceOrientation always return Portrait in AppDelegate iPad?UIInterfaceOrientation 总是在 AppDelegate iPad 中返回 Portrait?
【发布时间】:2012-02-07 15:08:13
【问题描述】:

我想在 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 中获取当前方向?请帮助我找到解决方案。提前致谢。

【问题讨论】:

    标签: ios ipad splash-screen uiinterfaceorientation


    【解决方案1】:

    阅读您的代码后,您似乎想要在应用启动时显示静态图像。无需任何代码也可以做到这一点。

    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。仅供参考。

    【讨论】:

    • 张先生感谢您的回答。在此代码之前,我只在 UIViewController 中保留了初始屏幕代码。顺便说一句,当我旋转应用程序时,启动画面不会改变它的方向。这就是我在 AppDelegate 中编写代码的原因。在 AppDelegate 中,我还编写了获取 LogInToken 的代码。我需要显示启动画面,直到我得到 loginToken。你能帮我么?谢谢。
    • 对不起,这可能太晚了 :-) 据我所知,有一个问题可能是 rootViewController.view 不会自行旋转。这意味着,您需要创建一个与 rootViewController.view 一样全尺寸的容器视图,并使其自动旋转标记为全宽和全高,然后,当您的设备方向发生变化时,您将能够自动旋转。
    【解决方案2】:

    您不应该在AppDelegate 上这样做,而应该在UIViewController 上这样做。在UIViewController 中,您可以通过课程为您提供的using the appropriate methods配置视图旋转设置部分)正确了解设备的位置。

    【讨论】:

    • Mr.Jack Boy 感谢您的回答。在此代码之前,我只在 UIViewController 中保留了初始屏幕代码。顺便说一句,当我旋转应用程序时,启动画面不会改变它的方向。这就是我在 AppDelegate 中编写代码的原因。在 AppDelegate 中,我还编写了获取 LogInToken 的代码。我需要显示启动画面,直到我得到 loginToken。你能帮我么?谢谢。
    • 好吧,你允许屏幕旋转吗?在: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    • Mr.Jack Boy 在您回答后我有信心解决我的问题。是的 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOr‌​在 UIViewController 中的方向方法。另一个问题是我正在调用 [viewcontrollerobj showSplash]; AppDelegate 中的方法来显示启动画面。然后我在 AppDelegate 中继续 XMLParser。在 didEndParsing Delegate 中,我尝试使用 [viewcontrollerobj hideSplash] 隐藏启动画面;但是,当控件达到此方法时,应用程序会崩溃。我该如何解决这个问题?希望你能理解我的问题。谢谢。
    • 嗯,你能告诉我错误吗?此外,您应该避免在 AppDelegate 中执行此类操作。您可以在专门为此设计的类上进行解析,并在解析完成后使用您的 UIViewController 接收响应。
    • 现在我解决了应用程序崩溃的问题。仍在努力以纵向模式在 Default-Landscape.png 中显示启动画面。当我在横向模式下启动应用程序时,启动画面仅在纵向模式下。请帮我。我跟着你的想法。我从 AppDelegate 中删除了代码,并在 UIViewController 中编写了 SplashScreen 代码。谢谢。我需要你的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 1970-01-01
    • 2012-01-08
    相关资源
    最近更新 更多