1
votes

Here is my setup: one navigation controller, two views

The first view, the rootview, displays the statusbar and navigation bar (portrait view). When the rootviewController senses rotation, it hides the nav bar and status bar and then it pushes view 2 onto the navigation controller (in landscape now).

This part works as expected.

When View2 viewcontroller senses rotation (back to portrait), it pops itself of the navigation controller, revealing view 1. View 1 then unhides the status bar and nav bar. From here, it gets weird. Depending on when I unhide the navigation bar, I get strange results. As you can see below (The beaker photo should be just below the navbar at the top of the screen).

I have tried unhiding the navigation bar in:

  • viewWillRotate/viewDidRotate of view 2
  • viewWillAppear/viewDidAppear of view 1
  • poptoRootView in the navigation controller (I subclassed just to try)

Nothing works. Any Idea what is going on? This should be simple, but maybe I am doing things in the wrong places.

botched screen

3

3 Answers

0
votes

Check your autoresizing mask on all views in your nib and make sure its all set properly. If you have anything the way its not supposed to be it will freak out on rotation.

0
votes

Not sure why it's necessary, but when you're swaping views, you must apply a transformation to your view (with only 1 view the iPhone does this for you), and you must set the bounds of it.

Here is the code that should work for you (on the willAnimateFirstHalfOfRotationToInterfaceOrientation):

#define degreesToRadians(x) (M_PI * (x) / 180.0)
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
    self.view = landscapeView;
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
    self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320);

} else {
    self.view = portraitView;
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
    self.view.bounds = CGRectMake(0.0, 0.0, 300, 480);
}
0
votes

In the end, I reworked my app. (to use a modal view controller)

But I came into similar issues, instead white space where the status bar was located.

I think both problems can be attributed to not talking to the Navigation Controller when rotating/resizing views (instead I was talking to the ViewController.

For details of how I solved the problem:

iPhone + CGAffineTransFormRotate(pi/2) + statusBarHidden:YES + presentModalViewController = 20 pixels of white space