1

I am having strange problems presenting modal views from landscape orientation. The problem can be recreated by simply starting with a new view-based application and doing the following:

  1. Create a new UIViewController subclass that will be presented. I named mine ModalViewController. Change the views background color to make the bug more noticeable.

  2. return YES; in both controllers shouldAutorotateToInterfaceOrientation:

  3. Add an IBAction to your main view to display the modal and hook this action up to a button in your main view controller.

    - (IBAction)showModal {  
      ModalViewController *vc = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];  
      [self presentModalViewController:vc animated:NO];  
      [vc release];  
    }
    

Now when you click the button from landscape mode you should see the problem. The entire view is shifted up and to the left.

Anyone else experiencing this problem or have any workarounds? I am having similar problems on the iPad.

alt text

Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
crayment
  • 46
  • 1
  • 5

3 Answers3

1

After noticing the view had the correct frame in viewDidAppear and was being messed up sometime later I ended up fixing this by implementing the following in ModalViewController. This assumes a CGRect instance variable named frame_.

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  frame_ = [[self view] frame];
  [self performSelector:@selector(fixFrame) withObject:nil afterDelay:0];
}

- (void)fixFrame {
  [[self view] setFrame:frame_];
}

I would say this is a bug.

crayment
  • 46
  • 1
  • 5
0
  [self presentModalViewController:vc animated:YES];  

Instead of disabling animation, Try enabling the animation.

Manjunath
  • 4,545
  • 2
  • 26
  • 31
  • That fixes the frame but unfortunately does not solve my problem. I am doing some custom animations in the modals viewDidAppear which are delayed to much if the modal animates in. – crayment Dec 16 '10 at 09:56
0

What autoresizing mask are you using? (You'll be setting this in the XIB file.) It looks like it's not attached to the right side of the screen.

Also, is your view taking into account the size of the status bar? (I note the gap at the bottom looks very similar in size to the status bar.)

You can simulate a lot of this in Interface Builder by pressing the arrow on the title bar of the view.

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152
  • In interface builder everything seems to work fine (using the little arrow). Try it for yourself with my download. The view has the standard autosizing mask for a view - everything red in interface builder. It also works fine if you rotate to landscape after the modal is presented. – crayment Dec 16 '10 at 10:46