1

I begin with a view-based app template. In the automatically created viewcontroller's xib (call it VC1), I add a button, and define in its interface/implementation:

- (IBAction)showVC2;

- (IBAction)showVC2 {
      [self presentModalViewController:[[VC2 alloc] init] animated:NO];
}

I then create VC2. In both implementations, I allow only landscape orientations. In both xibs, I set the views to landscape. In the info.plist file, I specify starting orientation as landscape right.

When I run the project in the simulator and press the button in VC1, VC2 is displayed, but a 20 pixel gap shows both on the lower edge and on the right edge. Notably, rotation causes the view to be placed correctly on screen after rotation completes.

This issue is similar to others: 1 2 3, though the solutions identified do not seem to work in the present case. The correct/expected behavior occurs if the modal view is presented with animation (I do not want the transition animated, however). This issue has persisted since last summer (iOS 3.1.3?). It continues with 4.3. The issue does not occur in portrait orientation.

Can anyone provide a solution or explanation for why such a simple modal viewcontroller presentation does not give the expected result?

EDIT: Xcode project

Community
  • 1
  • 1
Karl
  • 70
  • 2
  • 7

1 Answers1

-1

I just tried building what you suggested and have no problems with a gap. I don't know if there is a way for you to post all of your code or your project. If you can do that I will try and help.

Jamie
  • 5,090
  • 28
  • 26
  • Hi Jamie, I have edited my question to include a link to the Xcode project. – Karl Mar 12 '11 at 06:11
  • Thanks. Actually I see when I set animated to NO that it displays as you stated. Is there a reason you need the view controller presented modally? Can't you just do [self.view addSubview:secondViewCont.view]; ? – Jamie Mar 12 '11 at 07:45
  • :-( I was hoping I did something silly. I can certainly do as suggested and add my second view as a subview; in fact, I started to do so previously. But if I have _n_ views, then my rootViewController must handle those _n_ views, plus its own. This would seem to negate the utility of UIViewController. Alternatively, I could create objects to manage the views so that control of the views is more appropriately distributed, but then it seems like I'm reinventing the wheel (i.e. UIViewController). I have yet to find an example of what I'm attempting. Do you know of any? – Karl Mar 12 '11 at 07:57
  • I'm not sure what you mean. The point of presenting a view modally is to disable all other input until the modal view is dealt with. It gets presented and then dismissed. If you are putting a bunch of full screen views on, then you probably want each view to have its own controller, depending on what each view is doing, of course. – Jamie Mar 12 '11 at 08:02
  • Exactly. Since I'm not using a tab or navigation controller, I need a structured way of showing different (full) screens of content. It seems the most natural way of doing this is to have a rootViewController (VC1 in the example) able to show modal views (VC2, VC3, etc). Imagine VC2 as a menu screen with options 'new','open','save','email',etc. User makes a selection, then VC2 is dismissed by VC1 and the next view/viewController are presented by the rootViewController. Is this clearer, or am I still not making sense? – Karl Mar 12 '11 at 08:24