IPad Launch Orientation

After reading a lot of posts, I still haven't figured out how to solve this problem ...

The first view of my application is tableViewController. I am overriding

(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 

      

and it always returns YES.

If I hold my iPad in vertical orientation, it will rotate immediately after launching the application. However, if I put my iPad on the table, even though my home page is in landscape orientation, it launches in mordant orientation.

So, I guess the problem is, how can I get the orientation of my home page and run the application with that orientation?

+2


a source to share


4 answers


I had the same problem. There are some funky things going on with the first view controller you add to the window, and whatever orientation it is. Make sure all view controllers return YES for orientation if you want the first one to be opened with the correct orientation.



+1


a source


My app is openGL, but the way I worked 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 to rotate 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 am handling changes programmatically.

+1


a source


When the application starts, willRotateToInterfaceOrientation is used only if the Home screen is in landscape mode. This way we can determine the orientation when the device is "Face Up" or "Face Down". [UIDevice currentDevice]. Orientation works when the device is not parallel to the ground.

0


a source


I have used orientation figurine to orient my openglview, for example:

UIDeviceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;       
NSLog(@"%s: orientation: %i", _cmd, (int)orientation); 

      

0


a source







All Articles