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?
a source to share
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.
a source to share
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.
a source to share