问题
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