Search code examples
iosipadsplash-screenuiinterfaceorientation

UIInterfaceOrientation always return Portrait in AppDelegate 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 . 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.


Solution

  • 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.