How do I detect an iPad's interfaceRotation at the start?

£可爱£侵袭症+ 提交于 2020-01-03 10:44:10

问题


I'm having problems getting my iPad app to detect its interfaceOrientation in the first UIViewController I initialize (in code). In fact, if I trace for application.statusBarOrientation, that too returns 1 (UIInterfaceOrientationPortrait) even if I launched in landscape.

If I trace self.interfaceOrientation in my first UIViewController, it remains 1 until it gets to viewWillDisappear... Which is unfortunately too late!

Here's some code (even though there's not much to see):

In my appDelegate I have this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
     // show loading screen first
     [window addSubview:loadingScreenViewController.view];
     [window makeKeyAndVisible];

     NSLog(@"applicationDidBecomeActive:statusBarOrientation = %d", application.statusBarOrientation);
     return YES;
}

which traces 1 (portrait), even though I clearly see the status bar is landscape... and in the first view controller I have this:

- (void)viewDidLoad
{
    [super viewDidLoad];
     NSLog(@"self.interfaceOrientation = %d", self.interfaceOrientation);
}

which also traces 1, even in landscape mode.

Any ideas? Stumped here!

Thanks :)

:-Joe


回答1:


Here is the answer... Somewhat: (from Apple Dev Forums): .... "The app is always loaded as if the device is portrait, and then if the device is really landscape the app is told that the device has rotated. This is done so that nibs and code only need to create their UI in one orientation. Otherwise it might be necessary to have two UI layouts for each nib." .... it's not the answer I'd have liked, but that's how iOS works unfortunately!




回答2:


What does the app delegate report in applicationDidFinishLaunching? Because if it reports the correct value, you can always access the delegate to check the orientation.



来源:https://stackoverflow.com/questions/3382937/how-do-i-detect-an-ipads-interfacerotation-at-the-start

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