Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Windows Rotation Problem - iPhone / iPad

My app uses 2 UIWindows. The first shown has a TabBar controller with ViewControllers that only rotate to Portrait orientations. Up to here everything woks fine.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return (UIInterfaceOrientationIsPortrait(interfaceOrientation));
}

On the other window I have a UIViewController that rotates to all orientations.

The problem is that when I show the second window

[secondWindow makeKeyAndVisible];

And then return to the first one

[firstWindow makeKeyAndVisible];

The statusbar rotates to all directions and the event shouldAutorotateToInterfaceOrientation is not fired. How can i solve the problem?

like image 432
cesarnicola Avatar asked Aug 26 '10 20:08

cesarnicola


1 Answers

Its fine to have multiple UIWindows in one app, but the caveat here is that Apple's code seem to check through every UIWindow you have and see if the topmost view controller allows for a certain rotation. If any of those windows allow a rotation your status bar will rotate regardless of whether the UIWindow is frontmost or visible.

In my own app I hide the UIWindow I'm not using, and added a isHidden check in the relevant UIViewControllers to not allow rotation if the window is currently hidden.

like image 91
zai chang Avatar answered Oct 21 '22 08:10

zai chang