4
votes

I have an iPad application with a main view controller, which have a status bar and navigation bar on the top.

When I rotate this main view - everything is fine. But when I present a modal (full screen) view controller and rotate the device when its presented, this happens:

  1. The presented view controller is rotated as expected.

  2. When dismissed, the main view is still in the orientation which it was when presenting (wrong one), but the status bar is on top (like only the status bar was rotated).

  3. After playing with the device a bit, the orientation changes to what it should, but now the status bar does not have it's 20px margin on top - it is now overlapping the navigation bar, which looks awful.

Any ideas on what caused this strange situation?

EDIT: not using UINavigationController prevents the statusBar overlapping the navigation bar issue, but the rotation issue still exists.

2
Can you provide some code related to the presentation? Are you using one of the standard modal transition styles or doing a custom transition?azsromej
The modal presentation style is UIModalTransitionStyleCrossDissolve. nothing custom hereEliktz

2 Answers

4
votes

View orientations usually don't get automatically updated if they are not visible. You can manually set the orientation on viewWillAppear.

This link should set you off on the right foot.

1
votes

From the UIViewController Class Reference:

When a rotation occurs for a visible view controller, the willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods are called during the rotation. The viewWillLayoutSubviews method is also called after the view is resized and positioned by its parent. If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews method is called when the view becomes visible. Your implementation of this method can call the statusBarOrientation method to determine the device orientation.

So, you can use the viewWillLayoutSubviews method to rotate your presentingViewController according to the current statusBarOrientation. I haven't tested this code, but something like this should get you started:

- (void)viewWillLayoutSubviews {
    [self willRotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0];
    [self willAnimateRotationToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0];
}