UIInterfaceOrientation always return Portrait in AppDelegate iPad?

让人想犯罪 __ 提交于 2020-01-03 20:14:19

问题


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.


回答1:


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.




回答2:


After read your code, seems like what you want is to show a static image when app startup. There is way to do that without any code.

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

If you want to show any dynamic content as "splash", you may need to process it in a UIViewController.

For get current device orientation, you can read property: [UIDevice currentDevice].orientation. Just for your reference.



来源:https://stackoverflow.com/questions/8816252/uiinterfaceorientation-always-return-portrait-in-appdelegate-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!