5

I'm trying to present a view controller with its presentation style set to form sheet. However, when the view controller appears, it is positioned to the right of the screen, not in the center. I am not sure why this is happening, or what I should do. All of these coordinates are correct!

CGSize size = CGSizeMake(650, 550);

//custom init for ViewController so I can position stuff correctly
ViewController *vc = [[ViewController alloc] initWithSize:size];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:nav animated:YES];

nav.view.superview.frame = CGRectMake(0, 0, size.width, size.height);
nav.view.superview.center = self.view.center;

enter image description here

Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
  • Did you mess with the auto-rotation mechanism? It looks like the sheet is positioned where it would be if the Sim was turned so the home button was on the right – CodaFi Mar 17 '13 at 04:53
  • @CodaFi No, I haven't. The app is running in portrait mode, and that's where the sheet is positioned. When I remove the last two lines of code (responsible for resizing the sheet and centering it), the sheet is centered, however it is not the size I want (650 x 550). – Jack Humphries Mar 17 '13 at 19:59

1 Answers1

1

It seems that whenever I remove the last two lines, I get what I assume to be the behavior that you are looking for.

CGSize size = CGSizeMake(650, 550);

//custom init for ViewController so I can position stuff correctly
ViewController *vc = [[ViewController alloc] initWithSize:size];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:nav animated:YES];

I'm not sure exactly what you were trying to do with those two lines, but without them the view is centered.

Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
Jsdodgers
  • 5,253
  • 2
  • 20
  • 36
  • How do I size the view differently then? I want it to be 650 x 550. – Jack Humphries Mar 17 '13 at 19:58
  • Take a look at the answer here: http://stackoverflow.com/questions/8972990/how-to-resize-a-modalviewcontroller-with-uimodalpresentationpagesheet – Jsdodgers Mar 17 '13 at 21:05
  • 8
    On iOS7 Beta 5 neither UIModalTransitionStyleFlipHorizontal or UIModalTransitionStyleCoverVertical appears to get the form sheets centered. Only UIModalTransitionStyleCrossDissolve works. – Carlos Ricardo Aug 23 '13 at 14:27
  • Thanx Carols. You're right. I'm using Xcode 5 and iOS7 SDK final now. The problem is still there. I think it's a bug. – Ali Sep 22 '13 at 10:04
  • 2
    I have the same issue when trying to present a modal view controller with UIModalPresentationFormSheet with any transition style and call [self.firstTextfield becomeFirstResponder] in viewDidAppear... – knl Oct 10 '13 at 17:28