views:

621

answers:

2

After reading many posts, I still haven't got a clue how to solve this problem...

The first view of my app is a tableViewController. I override

(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 

and it always returns YES.

If I hold my iPad upright under landscape orientation, it rotates right after I launch the app. However, if I put my iPad flat on the table, even though my homepage is in landscape orientation, it launches in protrait orientation.

So I guess the problem is, how can I get the orientation of my homepage and launch my app with that orientation?

A: 

I had this same problem. There's some funky stuff that goes on with the first view controller you add to a window and whatever orientation it has. Make sure that the view controllers all return YES for orientations if you want the very first one to open with the right orientation

Paul Shapiro
+1  A: 

My app is openGL, but the way I handled this was to use notifications:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

// This is called right BEFORE the view is about to rotate. Here I'm using a notification message
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
        NSNotification* notification = [NSNotification notificationWithName:@"orientationIsPortrait" object:self];
        [[NSNotificationCenter defaultCenter] postNotification:notification];
    }
    else {
        NSNotification* notification = [NSNotification notificationWithName:@"orientationIsLandscape" object:self];
        [[NSNotificationCenter defaultCenter] postNotification:notification];
    }

}

willRotateToInterfaceOrientation is called right BEFORE it actually starts rotating the orientation.

Then in my EAGLView initWithFrame: I set up observers..

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewBecamePortrait:) name:@"orientationIsPortrait" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewBecameLandscape:) name:@"orientationIsLandscape" object:nil];

and in viewBecamePortrait and viewBecameLandscape I handle the changes programatically.

badweasel

related questions