UIInterfaceOrientation总是在AppDelegate iPad中返回Portrait? [英] UIInterfaceOrientation always return Portrait in AppDelegate iPad?

查看:191
本文介绍了UIInterfaceOrientation总是在AppDelegate iPad中返回Portrait?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to show the Splash Screen in iPad application. Before that i want to get the current device orientation Landscape or Portrait mode. I have used,

    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];
    }

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

in Appdelegate.m . The UIInterface orienation always detecting in Portrait mode only. I launched the app in Landscape mode but, the control always detecting Portrait mode only. How can i get the current orientation in AppDelegate.m? Please help me to find the solution. Thanks in advance.

推荐答案

你不应该在 AppDelegate 上这样做,而是在 UIViewController 上。在 UIViewController 中,您可以通过使用适当的方法配置视图旋转设置部分),该类为您提供。

You shouldn't do that on the AppDelegate, but rather on a UIViewController. In a UIViewController you can correctly know in what position the device is, by using the appropriate methods (Configuring the View Rotation Settings section) that the class gives you.

这篇关于UIInterfaceOrientation总是在AppDelegate iPad中返回Portrait?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆