views:

78

answers:

0

If a view is added to the window, orientation is set as portrait even if the device is in landscape. If the view is added in the app delegate, application:didFinishLaunchingWithOptions: method, then it works correctly. But if the view is added later it does not.

As an example, I have a routine to switch views. Simplest form is:

- (void)switchToNewViewController:(UIViewController *)newViewController { 
 if ([[window subviews]count]!=0) {
  [[[window subviews]objectAtIndex:0] removeFromSuperview];
 }
 [window addSubview:newViewController.view];
}

IF this is called from within didFinishLaunching, orientation is correct. If it is not, orientation is portrait.

Simplest case is within didFinishLaunching I have the following two lines

// The following line works
[self switchToNewViewController:fullScreenViewController];

// The following line which delays the method call until later results
// in incorrect orientation 
[self performSelector:@selector(switchToNewViewController:) withObject:fullScreenViewController afterDelay:0.1];

Is there a way to make the view have the proper orientation?