I created a subclass of UITabBarController, in order to hide tabBar and statusBar once in landscape mode. I successfully implemented the code to hide/show the tabBar, but the stausBar is driving me crazy. My current implementation works 100% but not for the first rotation, and I'm unable to figure out why. The code is the following:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
BOOL hide = (fromInterfaceOrientation == UIInterfaceOrientationPortrait ||
fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
[[UIApplication sharedApplication] setStatusBarHidden:hide withAnimation:UIStatusBarAnimationNone];
CGRect mainFrame = [[UIScreen mainScreen] applicationFrame];
[self.view setFrame:mainFrame];
}
In practice the first time I rotate my iPhone, the statusBar is correctly hide, but the frame is not correct (it has the 20px gap on the top). If I return to the portrait view from here, the layout will restore as expected, if then I rotate in landscape for the second time it will finally works as desired (no bars, pixel perfect layout!)... and from this point I can rotate my device N times and the views will always be presented in the right way... so, why the first time my code fails?!
Extra info you may need:
- root tab controllers are UINavigationControllers
- all my nested view controllers are properly configured to support orientation changes
- I'm testing using iOS 5